Show us your migration files.
Apr 1, 2020
5
Level 1
Build relation of two table and apply onDelete('cascade). It's not working
Hello Guys,
I am building the relation b/w two tables and apply the onDelete method but it' not work for me.
Error:
SQLSTATE[HY000]: General error: 1005 Can't create table laravel_cms.posts (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table posts add cons
traint posts_user_id_foreign foreign key (user_id) references users (id) on delete cascade).
Please read these line before answering.
- My primary key and foreign key has same data type and same size.
- I have index box columns.
- I assign nullable method to foiegn key but it does't work.
- I also assign unsigned method to foreign key but it does't work.
- My column has same schema object.
Level 73
table->id() is a bigInteger so all your foreign keys needs to be the same format.
Schema::table('posts', function (Blueprint $table) {
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
});
Please or to participate in this conversation.