Magento – Magento 2 : Foreign key constraint is incorrectly formed, ALTER TABLE customer_group

customerdatabaseforeign keymagento2

After upgrade from magento 2.1.7 to 2.2.3 and am stuck. I have tried everything.

In Pdo.php line 235:
SQLSTATE[HY000]: General error: 1025 Error on rename of './zwwnzwzjhe/#sql-1bd1_25f9' to './zwwnzwzjhe/customer_group' (errno:
150 – Foreign key constraint is incorrectly formed), query was: ALTER
TABLE customer_group MODIFY COLUMN customer_group_id int(10)
UNSIGNED NOT NULL AUTO_INCREMENT

In Pdo.php line 228: SQLSTATE[HY000]: General error: 1025 Error on rename of './zwwnzwzjhe/#sql-1bd1_25f9' to
'./zwwnzwzjhe/customer_group' (errno: 150 – Foreign key constraint is
incorrectly formed)

I am unable to delete this table or make any changes to this table …please help.

Thank you

Best Answer

To work around this, use either of these solutions. Both present risks of damaging the data integrity.

Option 1:

Remove constraints
Perform TRUNCATE
Delete manually the rows that now have references to nowhere
Create constraints

Option 2:

SET FOREIGN_KEY_CHECKS = 0; 
TRUNCATE table customer_group; 
SET FOREIGN_KEY_CHECKS = 1;
Related Topic