亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

SQLSTATE [42000]:語法錯誤或訪問沖突:1075不正確的表定義;默認值為0。

SQLSTATE [42000]:語法錯誤或訪問沖突:1075不正確的表定義;默認值為0。

PHP
MMTTMM 2021-05-02 16:38:53
遷移檔案$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不正確的表定義;默認值為0。只能有一個自動列,并且必須將其定義為鍵(SQL:創建表bookings(idint unsigned not null auto_increment主鍵,statusint不為null,date 日期不為null,time時間不為null,price十進制(8,2)不為null, instrumenttinyint unsigned不為null auto_increment主鍵, instrument_detailvarchar(255)不為null,created_at時間戳為null,updated_at時間戳為null)默認字符集utf8mb4整理utf8mb4_unicode_ci)而這下面SQLSTATE [42000]:語法錯誤或訪問沖突:1075不正確的表定義;默認值為0。只能有一個自動列,并且必須將其定義為鍵
查看完整描述

2 回答

?
撒科打諢

TA貢獻1934條經驗 獲得超2個贊

$table->unsignedTinyInteger('instrument', true);

第二個參數是布爾值,用于自動遞增,默認為false



查看完整回答
反對 回復 2021-05-21
?
白豬掌柜的

TA貢獻1893條經驗 獲得超10個贊

下句話:

$table->foreign('user_id')->references('id')->on('users');

只是告訴數據庫在父/外部列之間建立鏈接,但是為了做到這一點,該列必須先前存在,所以:

$table->unsignedInteger('user_id'); // first this
$table->foreign('user_id')->references('id')->on('users'); // then this

您應該為每個外鍵執行此操作。

筆記:

Laravel不需要您定義此鏈接,因為它不需要使用此鏈接,僅出于數據庫一致性的考慮。


查看完整回答
反對 回復 2021-05-21
  • 2 回答
  • 0 關注
  • 201 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號