Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.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
Laravel-表定义不正确;只能有一个自动列,必须将其定义为键;_Laravel - Fatal编程技术网

Laravel-表定义不正确;只能有一个自动列,必须将其定义为键;

Laravel-表定义不正确;只能有一个自动列,必须将其定义为键;,laravel,Laravel,在我的Laravel-8应用程序中,我得到了以下代码: public function up() { Schema::create('user_log_activities', function (Blueprint $table) { $table->bigIncrements('id'); $table->bigInteger('user_id')->nullable()->unsigned(); $table-

在我的Laravel-8应用程序中,我得到了以下代码:

public function up()
{
    Schema::create('user_log_activities', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->bigInteger('user_id')->nullable()->unsigned();
        $table->string('log_url', 300)->nullable();
        $table->string('log_method', 20)->nullable();
        $table->string('log_type', 50)->nullable();
        $table->string('subject', 200)->nullable();
        $table->string('subject_hint', 20)->nullable();
        $table->integer('company_id', 11)->nullable();
        $table->string('id_address', 64)->nullable();
        $table->string('agent', 300)->nullable();
        $table->timestamps();
    });
}
问题在于:

$table->bigInteger('user_id')->nullable()->unsigned()

用户id不是自动递增的,但我得到了以下错误:

PDOException::(“SQLSTATE[42000]:语法错误或访问冲突:1075表定义不正确;只能有一个 自动列,并且必须将其定义为键“)

我试过几种方法,但都不管用

我如何解决它


谢谢

如果用户id是外键,您可以使用外键方法定义:


如果用户id是外键,则可以使用外键方法定义:


问题是您正在将长度与整数一起使用。11计数为自动增量值

$table->integer('company_id', 11)->nullable();
去掉它的长度

$table->integer('company_id')->nullable();
$table->integer('company_id')->nullable();

如果是外键,则使用与用户id相同的值。问题是,您使用的是长度和整数。11计数为自动增量值

$table->integer('company_id', 11)->nullable();
$table->integer('company_id', 11)->nullable();
去掉它的长度

$table->integer('company_id')->nullable();
$table->integer('company_id')->nullable();
如果是外键,则使用与用户id相同的外键

$table->integer('company_id', 11)->nullable();
取代

取代