【发布时间】:2017-07-15 12:19:08
【问题描述】:
所以我试图在我的迁移文件中为 laravel 设置一个外键,这样用户表就很简单,但我试图使用 bigIncrements 而不是这样的站立增量。
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();
});
}
【问题讨论】:
-
尝试去掉外键语句末尾的
->unsigned()->index()
标签: php mysql laravel laravel-5