繁体   English   中英

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

[英]SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key

public function up()
{
    Schema::create('jadwal_praks', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('thnajrn_id', 10)->unsigned();
        $table->foreign('thnajrn_id')->references('id')->on('tahun_ajarans');
        $table->integer('prak_id', 10)->unsigned();
        $table->foreign('prak_id')->references('Prak_kode')->on('mata_praks');
        $table->integer('hari_id', 10)->unsigned();
        $table->foreign('hari_id')->references('id')->on('haris');
        $table->integer('jam_id', 10)->unsigned();
        $table->foreign('jam_id')->references('id')->on('jams');
        $table->integer('ruang_id', 10)->unsigned();
        $table->foreign('ruang_id')->references('id')->on('ruangs');
        $table->integer('kap_id', 10)->unsigned();
        $table->foreign('kap_id')->references('id')->on('kapasitas');

        $table->timestamps();
        $table->rememberToken();
    });
}

运行php artisan migrate

[Illuminate\\Database\\QueryException] SQLSTATE[42000]:语法错误或访问冲突:1075 表定义不正确; 只能有一个自动列,并且必须将其定义为键(SQL:创建表jadwal_praks ( id int unsigned not null auto_increment
主键, thnajrn_id INT无符号NOT NULL的auto_increment主键, prak_id INT无符号NOT NULL汽车_increment主键, hari_id INT无符号NOT NULL的auto_increment主键, jam_id INT无符号不NUL升AUTO_INCREMENT主键, ruang_id INT无符号NOT NULL的auto_increment主键, kap_id int 无符号
not null auto_increment 主键, created_at时间戳 null, updated_at时间戳 null, remember_token v archar(100) null) 默认字符集 utf8 collat​​e utf8_unicode_ci)

和这个

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

根据我的观察,我会说您应该从(例如)中删除添加到外部字段的default值:

$table->integer('thnajrn_id', 10)->unsigned(); 

到:

$table->integer('thnajrn_id')->unsigned();

PS:有类似的经验,我知道目前这适用于我在 Laravel 5.2 中使用的项目之一。*

希望这可以帮助 :)

当您使用$table->integer('thnajrn_id', 10)->unsigned() 这意味着您将第二个参数设置为 true 代表 AutoIncrement

尝试

table->integer('thnajrn_id')->length(10)->unsigned();

更多信息

当你使用$table->unsignedBigInteger('account_id')->nullable(); 你仍然会得到同样的错误,因为nullable()产生一个默认值会产生同样的错误。 所以总是把你的外键留空,既不能为nullable也不能default(0)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM