A table that provides primary keys used in another tables's foreign keys cannot be dropped unless PRAGMA foreign_keys = 0 #972
Replies: 4 comments 8 replies
-
I propose that #pragma foreign_keys be exposed through storage.pragma.foreign_keys of storage type. Yes it is delicate but necessary for easier migrations |
Beta Was this translation helpful? Give feedback.
-
Yes it works but you use not a proper way. The proper way is to drop both tables. Because |
Beta Was this translation helpful? Give feedback.
-
during sync_schema() the order of dropping tables may be incorrect and a table with dependency rows may be dropped which triggers an exception if foreign_keys == 1 thus making it impossible to synchronize schema... it happened to me in one of my tests.. What do you think? |
Beta Was this translation helpful? Give feedback.
-
or else each table may be tested with has_dependent_rows() and not dropped until we have dropped the dependent tables.... don't know seems like complicated algorithm - what do you think? |
Beta Was this translation helpful? Give feedback.
-
Hi,
On the topic of migration, I have found something useful to use together with sync_schema(true);
Say we have 2 tables Job and User and User has a foreign key into Job. If we make substantial changes to Job specially like adding/removing a CHECK or UNIQUE, then just executing sync_schema(true) does not change the table. We are forced to drop it and recreate it. However since PRAGMA foreign_keys == 1, the drop_table fails (throws).
Therefore here is my recipe for a solution:
This works!!
Regards,
Juan Dent
Beta Was this translation helpful? Give feedback.
All reactions