bcc-code / directus-schema-sync

The better way to sync your Directus schema and data between environments
Apache License 2.0
90 stars 4 forks source link

Foreign key error when changing a table primary key #2

Closed AlaaL closed 8 months ago

AlaaL commented 8 months ago

Describe the Bug

I have a table which i changed it's schema (i deleted the collection and recreated it) specifically the primary key column name, when applying the schema changes to production i could not because when the schema-sync trying to drop the old primary key to create a new one it fails because the primary key is used in foreign key (which i also changed to the new primary key)

"message": "alter tableikunsdropid- ER_FK_COLUMN_CANNOT_DROP_CHILD: Cannot drop column 'id': needed in a foreign key constraint 'ikuns_pricing_tag_ikuns_id_foreign' of table 'ikuns_pricing_tag'",

To Reproduce

Create a local Directus instance with at least two collections and they have a relation between each others. Apply the same instance to another instance, a production for example.

In local Instance delete the main collection and recreate it with the same name but different primary key name, and recreate the foreign key relation with the other collection.

Export schema. Import schema in production.

you get the error.

Version

1.2.2

Installed Extension Via

NPM Custom

u12206050 commented 8 months ago

Thanks for raising the issue although since we just utilise the schema import and export of Directus, this part of the can only be fixed in Directus. Do you mind opening up the issue here

AlaaL commented 8 months ago

Ok sure i thought that, but i wasn't sure.