Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Laravel 5.4中将外键bigInteger设置为bigIncrements_Php_Mysql_Laravel_Laravel 5 - Fatal编程技术网

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

Php 在Laravel 5.4中将外键bigInteger设置为bigIncrements,php,mysql,laravel,laravel-5,Php,Mysql,Laravel,Laravel 5,因此,我试图在我的迁移文件中为laravel设置一个外键,这样用户表很简单,但我尝试使用bigIncrements,而不是stand increments public function up() { Schema::create('users', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->bigIncrements('id')->unsigned(

因此,我试图在我的迁移文件中为laravel设置一个外键,这样用户表很简单,但我尝试使用bigIncrements,而不是stand increments

 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();
    });
}

问题是
bigingress
返回一个无符号的biginger。 为了工作,外键必须是带有
索引()

的无符号大整数,从以下位置删除
无符号()

$table->bigIncrements('id')->unsigned();
另一个迁移应该如下所示:

$table->bigInteger('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
....
$table->index('user_id');

原因是主要外部引用必须是同一类型

bigingress()
想要
unsignedbiginger()

increments()
想要
unsignedInteger()

如果您正在使用

$table->bigIncrements('id')作为用户表中的主键:

然后使用

$table->unsignedBigInteger('user_id'); as foreign key
如果您使用的是
$table->increments('id')作为用户表中的主键,然后使用

$table->unsignedInteger('user_id'); as freign key.



$table->increments(); creates just integer and $table->bigIncrements(); creates big integer. 
因此,引用类型必须相同


阅读更多内容

尝试删除外键语句末尾的
->unsigned()->index()
非常感谢您这么做。或者简单地使用
unsignedbiginger