Laravel-表定义不正确;只能有一个自动列,必须将其定义为键;
在我的Laravel-8应用程序中,我得到了以下代码: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-
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();
取代
取代