我正在尝试在 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'(错误号:150)(SQL:alter tableusers
add constraint users_practice_id_foreign外键(practice_id
)引用gp
(id
))(绑定:数组(
))