https://kotlinlang.org logo
#squarelibraries
Title
# squarelibraries
v

Vlad

03/18/2024, 4:33 PM
Hey guys. Not exactly SQLDelight question: I want to remove a column from SQLite table. As I understand it is still not available for mobile (well at least for android, since DROP column added for SQLite in 3.35.0 but android adapted that version only since API34). So we go old way: table_backup fill with old table data *drop old table rename backup table to old table. When I drop the old table - FOREIGN constraints with delete on null also triggered which is not need. Question is if I can "pause" FOREIGN constrains while migrating or is there are better recipe?
j

jw

03/18/2024, 4:47 PM
You should be able to put the PRAGMAs directly in the migration code you write
Copy code
PRAGMA foreign_keys = OFF;
Do migration 
PRAGMA foreign_keys = ON;
👀 1
v

Vlad

03/18/2024, 5:51 PM
Would be good. But seems like because of this from the Sqlite docs:
Copy code
This pragma is a no-op within a transaction; foreign key constraint enforcement may only be enabled or disabled when there is no pending BEGIN or SAVEPOINT.
it is not working. If I put it into the migration file - it just ignored and migration happens. If I put it into the Drivers "onUpgrade" it crashes:
Copy code
java.lang.IllegalStateException: Foreign Key Constraints cannot be enabled or disabled while there are transactions in progress.  Finish all transactions and release all active database connections first.
j

jw

03/18/2024, 6:09 PM
Interesting! I did not know that
6 Views