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
sqlite self table FOREIGN KEY constraint failed with ON DELETE RESTRICT when drop()/sync({force:true}) #11583
Comments
Thanks for the report, can you please convert your code into a sequelize-sscce so that we can easily see it working on all dialects except sqlite? |
Done ( sequelize/sequelize-sscce#18 ) |
Thanks! Great SSCCE. Do you have any suggestion on how Sequelize should handle this? Should Sequelize remove the foreign key constraint before deleting? |
I've tagged this as a feature because it would be something extra that Sequelize is doing since SQLite doesn't do it by itself. |
I'm new to both SQLite and sequelize so I can't suggest the best approach. I did Google a little bit before submitting my suggestions and they did make no sense... SQLite doesn't support to drop a column or FK... oh... crap... So the only suggestion that left on my list is: Parse the FK constraint and delete rows ourselves in the right order. To this suggestion, I added the note (before googling): "at this point, it should probably be a user addon in a different NPM or the user should switch to ON DELETE CASCADE" So I totally agree with you about the feature label! (if you still go ahead, and if there is nobody that already did this somewhere). After thinking about it my recommendation would be: Close the issue. I should have know SQLite limit. |
@Suisse00 I see... Thanks :) I will leave it open because perhaps it might be interesting to try to implement a workaround for this in Sequelize, however it would be much better if SQLite supported this natively; so I will tag this as a low priority feature. |
For some cases could help turning off foreign key constrait
|
@romannep Hmmm, perhaps this could be built-in the |
I think it is reasonable to build this into |
This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂 |
https://stackoverflow.com/a/5987838/6191913 Shall we update this accordingly? |
Issue Description
I created a nested table that refers to itself.
When it contains data, trying to execute the .drop() or .sync({force: true}) will trigger a constraint failure from sqlite.
What are you doing?
will output
What do you expect to happen?
Since I'm deleting the whole table, FK to the same table shouldn't trigger this FK constraint.
Note: I don't have a SQLite background, only a MSSQL/MYSQL. So this behavior is strange to me.
I did look into DROP TABLE documentation and they indeed talk about this behavior.
I could see why this ticket could be closed as won't do.
Environment
Issue Template Checklist
How does this problem relate to dialects?
Would you be willing to resolve this issue by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: