我真的不知道出了什么问题,但我不能用这个查询添加外键约束。
alter table `__acc_role_user` add constraint `__acc_role_user_user_id_foreign` foreign key (`user_id`) references `__acc_accounts` (`account_id`) on delete cascade on update cascade
我如何创建帐户表?
Schema::create('__acc_accounts', function($table)
{
$table->integer('account_id')->increments();
$table->integer('points')->default(0);
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
});
然后委托迁移(下面只有有问题的部分):
Schema::create('__acc_role_user', function (Blueprint $table) {
$table->integer('user_id')->unsigned();
$table->integer('role_id')->unsigned();
$table->foreign('user_id')->references('account_id')->on('__acc_accounts')
->onUpdate('cascade')->onDelete('cascade');
$table->foreign('role_id')->references('id')->on('__acc_roles')
->onUpdate('cascade')->onDelete('cascade');
$table->primary(['user_id', 'role_id']);
});