I have problem with add FOREIGN KEY to table catalog_product_flat_8 - Magento 1.9
When I try reindexing, I get:
Product Flat Data index process unknown error:
Exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table '#sql-4c36_d67'
I try add in MySQL
ALTER TABLE catalog_product_flat_8
ADD CONSTRAINT FK_CAT_PRD_FLAT_8_ENTT_ID_CAT_PRD_ENTT_ENTT_ID FOREIGN KEY (entity_id) REFERENCES catalog_product_entity (entity_id) ON DELETE CASCADE ON UPDATE CASCADE;
Still
1022 Can't write; duplicate key in table '#sql-4c36_1099
I check in information_schema
SELECT * FROM information_schema.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_SCHEMA = "magento_db" AND CONSTRAINT_NAME LIKE "FK_CAT_PRD_FLAT_8_ENTT_ID_CAT_PRD_ENTT_ENTT_ID"
but 0 records
select COLUMN_NAME, CONSTRAINT_NAME, REFERENCED_COLUMN_NAME,
REFERENCED_TABLE_NAME
from information_schema.KEY_COLUMN_USAGE
where TABLE_NAME = 'catalog_product_flat_8';
I have only PRIMARY KEY for entity_id
.
So, I check:
select *
from information_schema.table_constraints
where constraint_schema = 'magento_db'
Only 1 record with "flat_8" for entity_id (PRIMARY),
And I search "FK_CAT_PRD_FLAT_8_ENTT_ID_CAT_PRD_ENTT_ENTT_ID" in every tables from information_schema
Results:
`information_schema`.`INNODB_SYS_FOREIGN`
| ID |FOR_NAME |REF_NAME | N_COLS | TYPE |
| magento_db/FK_CAT_PRD_FLAT_8_ENTT_ID_CAT_PRD_ENTT_E... |magento_db/#sql-6756_19e0f | magento_db/catalog_product_entity | 1 | 5 |
`information_schema`.`INNODB_SYS_FOREIGN_COLS`
| ID | FOR_COL_NAME| REF_COL_NAME | POS |
| magento_db/FK_CAT_PRD_FLAT_8_ENTT_ID_CAT_PRD_ENTT_E... | entity_id | entity_id | 0 |
I have not idea, please help