-
Notifications
You must be signed in to change notification settings - Fork 3
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
Constraint foreign key exception when having conflicting operations inside one transaction #9
Comments
According to this answer and many others, we need to make these changes:
|
In order to make the first point work correctly, all foreign keys should be created as Changed here: 022636f This means that projects adopting these changes, should update their database version |
Some deeper research showed that room uses More info: https://sqlite.org/pragma.html#pragma_defer_foreign_keys |
In order to achieve this type of control over foreign keys, Changed here: 132af15 |
Further research showed that |
fix: foreign key behaviour inside a transaction Close #9
Problem
If we have several tables with foreign key relations, then inside one transaction do some operations influences on each other and get exception
android.database.sqlite.SQLiteConstraintException: FOREIGN KEY constraint failed (code 787 SQLITE_CONSTRAINT_FOREIGNKEY)
.Unlikely, in Room library the same tables and relations such transaction is considered valid.
Environment: kabin:
0.1.0-alpha04
;SQLite version (according to documentation):
3.39
(API 34).Example
We have 2 tables and a dao.
If we will invoke dao method, we will catch an exception.
Expected behavior: successful operations inside one transaction.
I guess this error is connected with
deferred
flag inForeignKey
.The text was updated successfully, but these errors were encountered: