-
-
Notifications
You must be signed in to change notification settings - Fork 254
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
accommodate self-referential FKs, document best practice for PRAGMA FOREIGN KEYS in batch #345
Comments
Michael Bayer (@zzzeek) wrote: the table "_alembic_batch_temp" gets renamed to "resources" as the final step. Does that part fail ? or is sqlite so lame that it leaves the FK pointing to nothing? |
Christian Benke (@peletiah) wrote: Unfortunately that step seems to fail, the reference to "_alembic_batch_temp" is the final result. Here's the full patch I apply (Adapted from ziggurat_foundations):
|
Michael Bayer (@zzzeek) wrote: ok in your env.py, what happens if you emit "PRAGMA foreign_keys=ON" on the connection? Basically if this proceeds without any errors, then what we might do is make self-ref FKs just refer to the as-yet-nonexistent table. but this is weird and might even be considered a SQLite bug (well of course it is, but a bug that sqlite would actually care about...which is less likely). |
Michael Bayer (@zzzeek) wrote: ah - yes this is the solution and I'd say we just document it: https://www.sqlite.org/lang_altertable.html
|
Christian Benke (@peletiah) wrote: Yes, that did the trick, thanks a lot! For reference how to add "PRAGMA foreign_keys=ON to env.py":
|
Michael Bayer (@zzzeek) wrote: right but funny thing, with FKs on, now batch will fail for a table that has other tables pointing to it. and that is much harder to solve. so here i think there's the need to:
|
Changes by Michael Bayer (@zzzeek):
|
Changes by Michael Bayer (@zzzeek):
|
Changes by Michael Bayer (@zzzeek):
|
Michael Bayer (@zzzeek) wrote: as a workaround for now, you can temporarily set PRAGMA FOREIGN KEYS in your migration script using op.execute(), then turn it off. because if you leave it on , subsequent batch migrations will likely break for tables that refer to a batch-migrated table, since we're dropping a table that they refer to. |
Michael Bayer (@zzzeek) wrote: so yeah the right way to do this is going to break it for you, it's that we generate the FK constraint pointing to the ultimate table name, which will break if you have PRAGMA FOREIGN KEYS turned on. This makes it consistent with non-self-referential FKs which will never work w PRAGMA FKS on. So that'll be 0.8.4. |
Christian Benke (@peletiah) wrote: Ok, thanks! I'll upgrade then. For now I've switched to postgres, which is not such a pita. |
Michael Bayer (@zzzeek) wrote:
→ da7d599 |
Changes by Michael Bayer (@zzzeek):
|
Migrated issue, originally created by Christian Benke (@peletiah)
On a sqlite-DB I'm trying to alter a table with
but the foreign key I end up with points to "_alembic_patch_temp" instead of "resources":
The text was updated successfully, but these errors were encountered: