Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with migrating this "2016_07_29_171128_create_foreign_keys" #283

Open
mrvx opened this issue Jul 24, 2020 · 7 comments
Open

Problem with migrating this "2016_07_29_171128_create_foreign_keys" #283

mrvx opened this issue Jul 24, 2020 · 7 comments

Comments

@mrvx
Copy link

mrvx commented Jul 24, 2020

Migrating: 2016_07_29_171128_create_foreign_keys

Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table chatter_discussion add constraint chatter_discussion_user_id_foreign foreign key (user_id) references users (id) on delete cascade on update cascade)

at /Users/veikoteekel/PhpstormProjects/pillamail2/pillamail/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {

664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|

Exception trace:

1 PDOException::("SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint")
/Users/veikoteekel/PhpstormProjects/pillamail2/pillamail/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458

2 PDOStatement::execute()
/Users/veikoteekel/PhpstormProjects/pillamail2/pillamail/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458

Please use the argument -v to see more details.

@baraegh
Copy link

baraegh commented Aug 27, 2020

same here

@baraegh
Copy link

baraegh commented Aug 27, 2020

I have fixed this issue by using increment('id') instead of id() in 2014_10_12_000000_create_users_table.php file
& I use $table->unsignedInteger('user_id'); instead of $table->integer('user_id')->unsigned();
in 2016_07_29_171118_create_chatter_discussion_table.php file

@JamieCee20
Copy link

That did work however, now this error responds after changing the unsignedBigIntegers.

General error: 1005 Can't create table dashhound.chatter_discussion (errno: 121 "Duplicate key on write or update") (SQL: alter table chatter_discussion add constraint chatter_discussion_chatter_category_id_foreign foreign key (chatter_category_id) references chatter_categories (id) on delete cascade)

@mahdi4k
Copy link

mahdi4k commented Nov 19, 2020

That did work however, now this error responds after changing the unsignedBigIntegers.

General error: 1005 Can't create table dashhound.chatter_discussion (errno: 121 "Duplicate key on write or update") (SQL: alter table chatter_discussion add constraint chatter_discussion_chatter_category_id_foreign foreign key (chatter_category_id) references chatter_categories (id) on delete cascade)

first you need to fresh database next use migrate

@JamieCee20
Copy link

That did work however, now this error responds after changing the unsignedBigIntegers.
General error: 1005 Can't create table dashhound.chatter_discussion (errno: 121 "Duplicate key on write or update") (SQL: alter table chatter_discussion add constraint chatter_discussion_chatter_category_id_foreign foreign key (chatter_category_id) references chatter_categories (id) on delete cascade)

first you need to fresh database next use migrate

I did manage to get it working eveentually, apologies for not updating the issue. I've since created my own due to it being a university project and looks good having my own.

@yazan-1999
Copy link

Migrating: 2016_07_29_171118_create_chatter_post_table
Migrated: 2016_07_29_171118_create_chatter_post_table (0.02 seconds)
Migrating: 2016_07_29_171128_create_foreign_keys

Illuminate\Database\QueryException

SQLSTATE[HY000]: General error: 1005 Can't create table forum.chatter_discussion (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table chatter_discussion add constraint chatter_discussion_user_id_foreign foreign key (user_id) references users (id) on delete cascade on update cascade)

at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667| // If an exception occurs when attempting to run a query, we'll format the error
668| // message to include the bindings with SQL, which will make this exception a
669| // lot more helpful to the developer instead of just the database's errors.
670| catch (Exception $e) {

671| throw new QueryException(
672| $query, $this->prepareBindings($bindings), $e
673| );
674| }
675|

  +12 vendor frames 

13 database/migrations/2016_07_29_171128_create_foreign_keys.php:17
Illuminate\Support\Facades\Facade::__callStatic()

  +21 vendor frames 

35 artisan:37
Illuminate\Foundation\Console\Kernel::handle()

increments('id'); $table->integer('chatter_category_id')->unsigned()->default('1'); $table->string('title'); $table->unsignedInteger('user_id'); $table->boolean('sticky')->default(false); $table->integer('views')->unsigned()->default('0'); $table->boolean('answered')->default(0); $table->timestamps(); }); } public function down() { Schema::drop('chatter_discussion'); } }

@yazan-1999
Copy link

help please ;(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants