Answer the question
In order to leave comments, you need to log in
How to fix General error: 1215 Cannot add foreign key constraint?
I'm trying to assign a foreign key, but when executing migrate, I get this error, I don't understand what the problem is.
Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `socialites` add constraint `socialites_user_id_foreign` foreig
n key (`user_id`) references `users` (`id`) on delete CASCADE)
General error: 1215 Cannot add foreign key constraint
public function up()
{
Schema::create('socialites', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('user_id')->index();
$table->string('provider_user_id');
$table->string('provider');
$table->timestamps();
});
Schema::table('socialites', function (Blueprint $table) {
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('CASCADE');
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question