Exception 'yii\db\Exception' with message 'SQLSTATE[HY000]: General error: 1553 Cannot drop index 'invoice_details_customer_id_countryCode_postCode_key': needed in a foreign key constraint
The SQL being executed was: DROP INDEX `invoice_details_customer_id_countryCode_postCode_key` ON `invoice_details`'
in /app/vendor/yiisoft/yii2/db/Schema.php:676
Error Info:
Array
(
[0] => HY000
[1] => 1553
[2] => Cannot drop index 'invoice_details_customer_id_countryCode_postCode_key': needed in a foreign key constraint
)
Caused by: Exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1553 Cannot drop index 'invoice_details_customer_id_countryCode_postCode_key': needed in a foreign key constraint'
in /app/vendor/yiisoft/yii2/db/Command.php:1302
P.S.
But if you first
$this->dropForeignKey('fk_invoice_details_customer_id_customers_id', '{{%invoice_details}}');
and only then
$this->dropIndex('invoice_details_customer_id_countryCode_postCode_key', '{{%invoice_details}}');
then it would work.
Error with migrate down
Initial state: schema.yaml
Terminal: ./yii gii/api generate this:
_m240130_080000_create_table_invoicedetails.php
./yii migrate -> works correctly
Reproduction steps: ./yii migrate/down -> gives errors
P.S.
But if you first
$this->dropForeignKey('fk_invoice_details_customer_id_customers_id', '{{%invoice_details}}');
and only then$this->dropIndex('invoice_details_customer_id_countryCode_postCode_key', '{{%invoice_details}}');
then it would work.