我的 laravel 遷移如下所示public function up(){ Schema::create('account_main', function (Blueprint $table) { $table->increments('user_sn')->primary(); $table->string('member_username', 20); $table->string('login_password', 255); $table->integer('login_count')->default('0')->unsigned(); });}當我運行“php工匠遷移”時,顯示錯誤“1068多個主鍵”。有人可以幫忙找到問題嗎?
2 回答
HUX布斯
TA貢獻1876條經驗 獲得超6個贊
你不需要,因為已經包含它了。
這就像在MySQL中你寫這個:->primary()->increments('...')
PK INT AUTO_INCREMENT PRIMARY KEY; PRIMARY KEY(PK)
您聲明的相同主鍵是同一個主鍵的兩倍
拉莫斯之舞
TA貢獻1820條經驗 獲得超10個贊
在類型中將定義為自動。所以不需要使用方法。Laravel Eloquent ORMincrementsprimary keyprimary()
如果該列是整數。
$table->increments('user_sn');如果列是字符串
$table->string('user_sn')->primary();如果希望任何其他列是唯一的(而不是主鍵)
$table->increments('user_sn');
$table->string('member_username', 20)->unique(); // cannot contain duplicate values- 2 回答
- 0 關注
- 124 瀏覽
添加回答
舉報
0/150
提交
取消
