小编Mar*_*Lee的帖子

在Laravel 5.4中将外键bigInteger设置为bigIncrements

因此,我试图在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();
    });
}
Run Code Online (Sandbox Code Playgroud)

当我执行另一个表时,我尝试向其中添加外键,但我收到一条错误消息,指出外键的格式不正确。我对方法感到困惑,因为我要匹配列类型。这是另一张桌子。

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();
    });
}
Run Code Online (Sandbox Code Playgroud)

php mysql laravel laravel-5

6
推荐指数
2
解决办法
6131
查看次数

标签 统计

laravel ×1

laravel-5 ×1

mysql ×1

php ×1