我在添加外鍵和執行 php artisan migrate 時遇到問題:新鮮
有錯誤
("SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'id_rso'")
這是我的遷移表:
public function up()
{
Schema::enableForeignKeyConstraints();
Schema::create('dso', function (Blueprint $table) {
$table->string('id_dso',30);
$table->unsignedBigInteger('id_rso');
$table->foreignId('id_rso')->constrained('rso');
$table->smallInteger('id_focus');
$table->smallInteger('id_wilayah');
$table->smallInteger('id_grup_wilayah');
$table->string('nama_dso',50);
$table->string('created_by',50)->nullable();
$table->timestamp('created_date',$precision = 0);
$table->string('modified_by',50)->nullable();
$table->timestamp('modified_date',$precision = 0)->nullable()->default(null);
$table->boolean('status')->default(true);
$table->timestamps();
$table->primary('id_dso');
});
}
我將 mysql 用于資料庫和 Laravel 8
uj5u.com熱心網友回復:
$table->unsignedBigInteger('id_rso');
$table->foreignId('id_rso')->constrained('rso');
而不是這樣,只需寫:
$table->foreignId('id_rso')->constrained('rso');
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/329493.html
