laravel 數據庫遷移中integer類型是無法指定長度.

laravel數據庫遷移中integer類型是無法指定長度的,很多小夥伴對integer類型傳遞第二個參數後會發現遷移報以下錯誤

Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key

查看了sql代碼後發現通過integer指定長度創建的子段自動添加了auto increament 以及 primary key 屬性

int not null auto_increment primary key

查看源代碼後發現integer方法的第二個參數並不是指定長度,而是是否設置auto increment,所以integer方法無法指定子段長度,默認爲11。


    public function integer($column, $autoIncrement = false, $unsigned = false)
        {
        return $this->addColumn('integer', $column, compact('autoIncrement', 'unsigned'));
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章