所以我試圖在我的laravel遷移文件中設置一個外鍵,所以用戶表很簡單,但我試圖使用bigIncrements而不是站點增量。在Laravel 5.4中設置外鍵bigInteger 5.4
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->bigIncrements('id')->unsigned();
$table->string('user_id')->unique();
$table->string('avatar');
$table->string('name');
$table->string('email')->unique();
$table->string('password')->nullable();
$table->rememberToken();
$table->timestampsTz();
});
}
而當我做另一個表時,我嘗試添加外鍵給它,我得到一個錯誤,說外鍵被錯誤地形成。我很困惑,因爲我匹配列類型。這是另一張桌子。
public function up()
{
Schema::create('social_logins', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->bigIncrements('id');
$table->bigInteger('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->unsigned()->index();
$table->string('provider', 32);
$table->string('provider_id');
$table->string('token')->nullable();
$table->string('avatar')->nullable();
$table->timestamps();
});
}
儘量擺脫'的 - >無符號() - >指數()'末的外鍵聲明 – ntzm