【发布时间】:2013-11-19 18:51:11
【问题描述】:
我正在尝试在 Laravel 4 上的两个表 User 和 GP 之间创建外键约束。一个用户可以与多个 GP 相关联。外键是users表中的'Practice_ID',与GP表中的ID相关联。
public function up()
{
// Creates GP table
Schema::create('gp', function($ta)
{
$ta->bigIncrements('id');
$ta->string('address_1');
$ta->string('address_2');
$ta->string('address_3');
$ta->string('post_code');
$ta->timestamps();
});
// Creates the users table
Schema::create('users', function($table)
{
$table->increments('id');
$table->string('username');
$table->string('email');
$table->string('password');
$table->string('confirmation_code');
$table->boolean('confirmed')->default(false);
$table->bigInteger('practice_id');
$table->foreign('practice_id')->references('id')->on('gp');
$table->timestamps();
});
// Creates password reminders table
Schema::create('password_reminders', function($t)
{
$t->string('email');
$t->string('token');
$t->timestamp('created_at');
});
}
我得到的错误是:
[例外]
SQLSTATE[HY000]:一般错误:1005 无法创建表 'doctor.#sql-3ac_a4' (errno: 150) (SQL: alter tableusersadd 约束 users_practice_id_foreign 外键 (practice_id) 参考gp(id)) (绑定: 数组 (
))
【问题讨论】:
标签: foreign-keys migration laravel-4