我一直在这里寻找答案,但似乎没有任何工作。我已经完成了Laravel和Sentry 2的基本安装。首先,我已经添加了此迁移,以将user_id列添加到users表中。Laravel迁移的外键问题
Schema::table('users', function(Blueprint $table)
{
$table->integer('client_id')->unique;
});
然后,接下来我创建了我的客户端表,并在不同的迁移中使用以下内容。
Schema::create('clients', function(Blueprint $table)
{
$table->increments('id');
$table->timestamps();
$table->integer('client_id')->unique;
$table->string('client_name');
$table->date('expiry');
$table->integer('cals');
});
最后我创建在以下迁移
Schema::table('users', function(Blueprint $table)
{
$table->foreign('client_id')
->references('client_id')->on('clients')
->onDelete('cascade');
});
误差即时得到如下。
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `users` add constraint use
rs_client_id_foreign foreign key (`client_id`) references `clients` (`client_id`) on delete cascade)
我有点卡在我应该找的东西,他们都应该是索引?
当您手动运行它们(即使用MySQL客户端或phpmyadmin)时,这些查询是否工作? – Kryten
在phpmyadmin中说没有定义索引。 – Nathan