这是我的桌子:
用户表
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('username')->unique();
$table->string('password');
$table->integer('subscriber_id')->unsigned();
$table->rememberToken();
$table->timestamps();
$table->foreign('subscriber_id')
->references('id')
->on('subscribers');
});
}
用户表
public function up()
{
Schema::create('subscribers', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->nullable();
$table->timestamps();
});
}
每次我“ php artisan migration”时,此消息总是提示并阻止我进行迁移:
Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1005 Can't create
table `emade`.`#sql-de4_9e` (errno: 150 "Foreign key constraint is incorrectly formed")
(SQL: alter table `users` add constraint `users_subscriber_id_foreign` foreign key (`subs
criber_id`) references `subscribers` (`id`))
我只是对以上返回的行感到困惑:
1. 无法创建表'emade'-'emade'不是我的表,而是我的数据库
2. users_subscriber_id_foreign ?
我花了很多时间解决这个问题。我真的不知道发生了什么,先生,请帮忙。