[英]SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition
[英]SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition;
遷移文件
$table->increments('id');
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('band_id')->references('id')->on('bands');
$table->foreign('genre_id')->references('id')->on('genres');
$table->foreign('cate_id')->references('id')->on('cates');
$table->foreign('type_id')->references('id')->on('types');
$table->integer('status');
$table->date('date');
$table->time('time');
$table->decimal('price');
$table->tinyIncrements('instrument');
$table->string('instrument_detail',255);
$table->timestamps();
運行php artisan后遷移
SQLSTATE [42000]:語法錯誤或訪問沖突:1075表定義不正確; 只能有一個自動列,它必須被定義為一個鍵(SQL:create table
bookings
(id
int unsigned not null auto_increment primary key,status
int not null,date
date not null,time
time not null,price
decimal(8) ,2)not null,instrument
tinyint unsigned not null auto_increment primary key,instrument_detail
varchar(255)not null,created_at
timestamp null,updated_at
timestamp null)默認字符集utf8mb4 collate utf8mb4_unicode_ci)
以下是這個
SQLSTATE [42000]:語法錯誤或訪問沖突:1075表定義不正確; 只能有一個自動列,必須將其定義為鍵
$table->unsignedTinyInteger('instrument', true);
第二個參數是自動增量的bool,默認為false
下一句話:
$table->foreign('user_id')->references('id')->on('users');
只是告訴db在父/外部列之間建立鏈接,但為了做到這一點,列必須先存在,所以:
$table->unsignedInteger('user_id'); // first this
$table->foreign('user_id')->references('id')->on('users'); // then this
您應該為每個外鍵執行此操作。
注意:
Laravel不需要你定義這個鏈接因為它沒有使用它,只是為了數據庫一致性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.