laravel SQLSTATE[42000]:语法错误或访问冲突:1075 表定义不正确;只能有一个自动列,并且必须将其定义为键
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42053392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
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
提问by Muhammad Adnan Syarief
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();
});
}
After run php artisan migrate
运行后 php artisan migrate
[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto co lumn and it must be defined as a key (SQL: create table
jadwal_praks
(id
int unsigned not null auto_increment
primary key,thnajrn_id
int unsigned not null auto_increment primary key,prak_id
int unsigned not null auto _increment primary key,hari_id
int unsigned not null auto_increment primary key,jam_id
int unsigned not nul l auto_increment primary key,ruang_id
int unsigned not null auto_increment primary key,kap_id
int unsigned
not null auto_increment primary key,created_at
timestamp null,updated_at
timestamp null,remember_token
v archar(100) null) default character set utf8 collate utf8_unicode_ci)
[Illuminate\Database\QueryException] SQLSTATE[42000]:语法错误或访问冲突:1075 表定义不正确;只能有一个自动列并且它必须定义为一个键(SQL: create table
jadwal_praks
(id
int unsigned not null auto_increment
primary key,thnajrn_id
int unsigned not null auto_increment primary key,prak_id
int unsigned not null auto _increment primary key,hari_id
int unsigned not null auto_increment 主键,jam_id
int unsigned not null l auto_increment 主键,ruang_id
int unsigned not null auto_increment 主键,kap_id
int unsigned
not null auto_increment 主键,created_at
timestamp null,updated_at
timestamp null,remember_token
v archar(100) null) 默认字符集 utf8 collate utf8_unicode_ci)
And this
和这个
[PDOException] 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
[PDOException] SQLSTATE[42000]:语法错误或访问冲突:1075 不正确的表定义;只能有一个自动列,并且必须将其定义为键
回答by Oluwatobi Samuel Omisakin
With my observation, I would say you should remove default
value you added to the your foreign fields from (for example):
根据我的观察,我会说您应该default
从(例如)中删除您添加到外部字段的值:
$table->integer('thnajrn_id', 10)->unsigned();
To:
到:
$table->integer('thnajrn_id')->unsigned();
PS: With a similar experience, I know presently this works with one of the projects I work with in Laravel 5.2.*
PS:有类似的经验,我知道目前这适用于我在 Laravel 5.2 中使用的项目之一。*
Hope this helps :)
希望这可以帮助 :)
回答by benson Njung'e
When you use $table->integer('thnajrn_id', 10)->unsigned()
; this means your setting the second parameter as true which represents AutoIncrement
当你使用$table->integer('thnajrn_id', 10)->unsigned()
; 这意味着您将第二个参数设置为 true 代表 AutoIncrement
try
尝试
table->integer('thnajrn_id')->length(10)->unsigned();