Syntax error or access violation: 1072 Key column 'school_id' doesn't exist in table (SQL: alter table `competitors` add constraint `competitors_school_id_foreign` foreign key (`school_id`) r eferences `schools` (`id`) on delete cascade) code example

Example: Syntax error or access violation: 1072 Key column 'user_id' doesn't exist in table (SQL: alter table `groups` add constraint `groups_user_id_foreign` foreign key (`user_id`) references `users` (`id`))

// You forgot to create the column before creating the relationship
// Do something like (add unsigned before the relationship):

$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');

Tags:

Php Example