我是laravel的新手。我试图将外键放在familymembers表中。但无法正确迁移。发生以下错误。我尝试了很多不同的更改来解决以下错误。但我不能这样做。这不是一个重复的问题。帮我...帮助...
在Connection.php第647行:
SQLSTATE [HY000]:常规错误:1215无法添加外键约束
(SQL: alter table `familymembers` add constraint `familymemb ers_user_id_foreign` foreign key (`user_id`) references `all_users` (`id`))
在Connection.php第449行:
SQLSTATE [HY000]:常规错误:1215无法添加外键约束
create_familymembers_table_migrations:
Schema::create('familymembers', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('fullName');
$table->string('relationship');
$table->string('gender');
$table->date('dob');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('all_users');
$table->timestamps();
});
create_all_users_table_migrations:
Schema::create('all_users', function (Blueprint $table) {
$table->increments('id');
$table->string('nameWithInitials');
$table->string('callingName');
$table->string('email');
$table->integer('contactNo');
$table->string('password');
$table->string('type');
$table->string('addNo');
$table->string('addStreet');
$table->string('addCity');
$table->string('intentToJoin');
$table->string('region');
$table->timestamps();
});
提前致谢。
确保迁移文件的顺序正确。
例如all_users
然后familymembers
。