【发布时间】:2014-04-07 08:30:18
【问题描述】:
我正在尝试创建一个数据透视表来保存一些基本 ACL 功能的关系数据。
迁移类:
Schema::create('group_user', function($table)
{
$table->increments('id');
$table->unsignedInteger('group_id');
$table->unsignedInteger('user_id');
$table->timestamps();
$table->softDeletes();
});
Schema::table('group_user', function($table)
{
$table->foreign('group_id')
->reference('id')->on('groups');
$table->foreign('user_id')
->reference('id')->on('users');
});
运行迁移命令后,出现以下错误:
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at li
ne 1 (SQL: alter table `group_user` add constraint group_user_group_id_foreign foreign key (`group_id`) references `groups` ())
如您所见,添加外键约束的 SQL 语法缺少引用表的“id”列名。这是 Laravel 中的错误还是我的架构代码有问题?
【问题讨论】: