Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

foreign key constraint #141

Open
boo-code opened this issue Jan 22, 2025 · 4 comments
Open

foreign key constraint #141

boo-code opened this issue Jan 22, 2025 · 4 comments
Labels
directus-related This issue is related to Directus itself

Comments

@boo-code
Copy link

Syncing stops because of foreign key constraint between two collections. directus-extension-sync shows error in console and crashes.

Solution would be to run "SET FOREIGN_KEY_CHECKS=0;" before pushing to DB, and then "SET FOREIGN_KEY_CHECKS=1;" when push is done. But how to set these additional DB commands in config or directus-extension-sync module itself?

@boo-code
Copy link
Author

errors: [
{
"message": "alter table cluster_analysis_data modify product int null - Cannot change column 'product': used in a foreign key constraint 'cluster_analysis_data_product_foreign'",
"extensions": {
"code": "INTERNAL_SERVER_ERROR"
}
}
]
response: {}

@EdouardDem EdouardDem added the directus-related This issue is related to Directus itself label Jan 23, 2025
@EdouardDem
Copy link
Member

Hi @boo-code

Solution would be to run "SET FOREIGN_KEY_CHECKS=0;" before pushing to DB, and then "SET FOREIGN_KEY_CHECKS=1;" when push is done. But how to set these additional DB commands in config or directus-extension-sync module itself?

No, you can't inject DB commands during push.

It seems that you are trying to run a migration of schema with existing data. This is related to the schema snapshot of Directus, used by Directus-Sync.

@boo-code
Copy link
Author

Destination is completely empty and has no data at all. I should check something in source here where pull was made from?

@boo-code
Copy link
Author

If destination database is empty, sync is working. If destination already contains tables (even empty from first sync), sync stops because of foreign key constraints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
directus-related This issue is related to Directus itself
Projects
None yet
Development

No branches or pull requests

2 participants