迁移回滚后无法重新迁移 Laravel 5.2
Cannot remigrate migration after migration rollback Laravel 5.2
美好的一天,我是新手 laravel 我正在执行迁移回滚并且已成功完成
Rolled back: 2018_02_22_172102_adding_fk_constrains_products_to_product_types_and_service_sub_types_table
但是当我尝试重新迁移时遇到了以下错误。顺便说一句,我不想删除该列,因为它已经存在并且我不想丢失该列中的现有数据。我只想在这些表之间添加约束
[Illuminate\Database\QueryException]
SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table '#sql-2fc8_17c' (SQL: alter table products
add constraint products_product_type_id_foreign
foreign key (product_type_id
) references product_types
(id
) on update cascade)
[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table '#sql-2fc8_17c'
Table Non_unique Key_name Seq_in_index Column_name
-------- ---------- ---------------------------------- ------------ -------------------
products 0 PRIMARY 1 id
products 1 products_product_type_id_index 1 product_type_id
products 1 products_service_sub_type_id_index 1 service_sub_type_id
这是我的迁移代码
public function up()
{
Schema::table('products',function (Blueprint $table){
$table->integer('product_type_id')->unsigned()->index()->change();
$table->foreign('product_type_id')->references('id')->on('product_types')->onUpdate('cascade');
$table->integer('service_sub_type_id')->nullable()->unsigned()->index()->change();
$table->foreign('service_sub_type_id')->references('id')->on('service_sub_types')->onUpdate('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('products', function(Blueprint $table){
$table->dropForeign(['product_type_id']);
$table->dropForeign(['service_sub_type_id']);
});
}
我只是在迁移中删除了以下代码
$table->integer('product_type_id')->unsigned()->index()->change();
$table->integer('service_sub_type_id')->nullable()->unsigned()->index()->change();
public function up()
{
Schema::table('products',function (Blueprint $table){
//$table->integer('product_type_id')->unsigned()->index()->change();
$table->foreign('product_type_id')->references('id')->on('product_types')->onUpdate('cascade');
//$table->integer('service_sub_type_id')->nullable()->unsigned()->index()->change();
$table->foreign('service_sub_type_id')->references('id')->on('service_sub_types')->onUpdate('cascade');
});
}
当我重新迁移时,它已成功迁移..
美好的一天,我是新手 laravel 我正在执行迁移回滚并且已成功完成
Rolled back: 2018_02_22_172102_adding_fk_constrains_products_to_product_types_and_service_sub_types_table
但是当我尝试重新迁移时遇到了以下错误。顺便说一句,我不想删除该列,因为它已经存在并且我不想丢失该列中的现有数据。我只想在这些表之间添加约束
[Illuminate\Database\QueryException] SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table '#sql-2fc8_17c' (SQL: alter table
products
add constraintproducts_product_type_id_foreign
foreign key (product_type_id
) referencesproduct_types
(id
) on update cascade)[PDOException] SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table '#sql-2fc8_17c'
Table Non_unique Key_name Seq_in_index Column_name
-------- ---------- ---------------------------------- ------------ -------------------
products 0 PRIMARY 1 id
products 1 products_product_type_id_index 1 product_type_id
products 1 products_service_sub_type_id_index 1 service_sub_type_id
这是我的迁移代码
public function up()
{
Schema::table('products',function (Blueprint $table){
$table->integer('product_type_id')->unsigned()->index()->change();
$table->foreign('product_type_id')->references('id')->on('product_types')->onUpdate('cascade');
$table->integer('service_sub_type_id')->nullable()->unsigned()->index()->change();
$table->foreign('service_sub_type_id')->references('id')->on('service_sub_types')->onUpdate('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('products', function(Blueprint $table){
$table->dropForeign(['product_type_id']);
$table->dropForeign(['service_sub_type_id']);
});
}
我只是在迁移中删除了以下代码
$table->integer('product_type_id')->unsigned()->index()->change();
$table->integer('service_sub_type_id')->nullable()->unsigned()->index()->change();
public function up()
{
Schema::table('products',function (Blueprint $table){
//$table->integer('product_type_id')->unsigned()->index()->change();
$table->foreign('product_type_id')->references('id')->on('product_types')->onUpdate('cascade');
//$table->integer('service_sub_type_id')->nullable()->unsigned()->index()->change();
$table->foreign('service_sub_type_id')->references('id')->on('service_sub_types')->onUpdate('cascade');
});
}
当我重新迁移时,它已成功迁移..