larave 使用migrate的時候報了一個錯誤
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
原因:
在創建表的時候,其中一個字段寫成了
$table->integer('Phone',11)->unique()->nullable();
但實際上,他這個類裏面所有的關於int類型的構造全都是自己加了autoIncrement,導致和ID衝突了,畢竟一個表不能有兩個自增
public function integer($column, $autoIncrement = false, $unsigned = false) {
return $this->addColumn('integer', $column, compact('autoIncrement', 'unsigned'));
}
第二個參數是 是否指定該字段是 autoincrement,按理說,他默認值是false,但是在創建的時候寫了個長度11,於是整型11轉換爲bool就是true,因此報錯