Does `PRAGMA defer_foreign_keys=ON` not
Does
PRAGMA defer_foreign_keys=ON
not disable on update
and on delete
actions? Kinda weird when SQLite often requires recreating tables (and thus triggering those actions)8 Replies
@Max (@rozenmd) Can you clarify? I'm really stuck on this one.
@Gerbuuun can you explain what you're trying to do + provide a repro? I don't follow
This issue describes it very well https://github.com/cloudflare/workers-sdk/issues/5438
GitHub
🚀 Feature Request: Allow turning off foreign key check while migrat...
Some table altering tasks in SQLite cannot be achieved without replacing it with a new table (by dropping - recreating the table) (like adding foreign keys, changing primary keys, updating column t...
And point 7 of the sqlite docs https://www.sqlite.org/lang_altertable.html
I just need a confirmation if this works as intended or that I'm going crazy
@geelen would know, but he's out of office until Tuesday
also I don't see
on update
or on delete
in your example in the github issue
unclear what
Rows are still deleted or set to null.refers to - which rows, in which table?
Lets say you have a user and a post table. Where posts are related to a user.
If I want to for example change the
name
column in the user
table to have a default value I need to recreate the table due to sqlite limitations:
(this procedure is described in the sqlite docs)
But due to the ON DELETE cascade
defined foreign key in the post
table, all posts referenced to any user are deleted (because we deleted the old table but created a new one with the same data).
PRAGMA foreign_keys=OFF;
or PRAGMA defer_foreign_keys=ON;
are supposed to disable this behavior right? But even if I use those pragma statements the cascading still happens
Thanks for looking into itLooked into this today,
PRAGMA legacy_alter_table=ON
was supposed to have fixed this: https://github.com/cloudflare/workerd/pull/2063
Can't seem to make the example in the PR work, though - will investigate furtherGitHub
sqlite: allow PRAGMA legacy_alter_table by smerritt · Pull Request ...
There's certain kinds of schema changes that are really painful to do in SQLite; this makes things a little easier.
For example, let's say you want to change the "users.email" col...
Seems a bit weird to me. The SQLite docs state
PRAGMA legacy_alter_table=OFF
is the default and they document the migration procedure without any mention of turning on legacy_alter_table
for it to work