[英]Laravel 4 - Artisan error SQLSTATE[42000]
我正在嘗試為我的users表創建一個新的遷移,我有以下架構:
Schema::create('users', function($t) {
$t->increments('id');
$t->string('username', 16);
$t->string('password', 64);
$t->integer('role', 64);
$t->timestamps();
});
當我嘗試從終端運行php artisan migrate時,我收到以下錯誤:
[例外]
SQLSTATE [42000]:語法錯誤或訪問沖突:1075表定義不正確; 只能有一個自動列,它必須被定義為一個鍵(SQL:create tableusers
(id
int unsigne d not null auto_increment primary key,username
varchar(16)not null,password
varchar(64)no t null,role
int not null auto_increment primary key,created_at
timestamp default 0 not null,updated_at
timestamp default 0 not null))(Bindings:array(
))
該錯誤與“角色”字段有關,因為當刪除它時,它似乎運行正常。
在此先感謝任何幫助或見解。
integer
的第二個參數是自動遞增標志。
public function integer($column, $autoIncrement = false, $unsigned = false)
https://github.com/laravel/framework/blob/5.4/src/Illuminate/Database/Schema/Blueprint.php#L510
$t->integer('role', false);
這解決了它。
不允許整數的長度屬性。移動它並嘗試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.