外键 Laravel 8 的迁移 Table
Migration Table for Foreign Key Laravel 8
我在添加外键和执行 php artisan migrate : fresh
时遇到问题
有错误
("SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'id_rso'")
这是我的迁移 table :
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
$table->unsignedBigInteger('id_rso');
$table->foreignId('id_rso')->constrained('rso');
代替这个,只写:
$table->foreignId('id_rso')->constrained('rso');
我在添加外键和执行 php artisan migrate : fresh
时遇到问题有错误
("SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'id_rso'")
这是我的迁移 table :
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
$table->unsignedBigInteger('id_rso');
$table->foreignId('id_rso')->constrained('rso');
代替这个,只写:
$table->foreignId('id_rso')->constrained('rso');