I'm trying to create a pivot table to hold some relationship data for some basic ACL functionality.
The migration class:
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');
});
After running the migration command, I get the following error:
[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` ())
As you can see, the SQL syntax to add the foreign key constraint is missing the 'id' column name for the referenced table. Is this a bug in Laravel or is there something wrong with my schema code?