Explicit usage of schema in models and foreign keys fails in public schema with postgres #1129
Replies: 1 comment 2 replies
-
it's actually not a bug.
it is! Alembic's docs don't point out to this, it would likely be a good idea if they did have a little section on models with alternate schema names, but the bulk of this documentation is in the SQLAlchemy docs where it's assumed that's where people are building out models that use schema names, however, it's in reflection docs, so some more cross linking would be helpful here. The general idea of how reflection interacts with schemas, where there is a "default" schema name, is here: https://docs.sqlalchemy.org/en/14/core/reflection.html#reflection-schema-qualified-interaction Then, and you might want to just skip to this depending on how much reading you want to do, is the PostgreSQL-specific version of this, where the search_path thing tends to bring this up to 11: https://docs.sqlalchemy.org/en/14/dialects/postgresql.html#remote-schema-table-introspection-and-postgresql-search-path The tl;dr is:
Can you do it differently? Sure! but 1 and 2 above are the "normal" way. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
I have two models, whereas the second one has a foreign key to the first one.
For models and foreign keys I use explicitly the schema public
I create the revisions and apply them with
alembic upgrade head
.Everything is fine.
Then I create another revision
alembic revision --autogenerate --message "wtf"
Expected behavior
Since there are no changes I expect a revision file with empty
updrade
anddowngrade
methods.Actual behavior
Alembic detects the following changes, but there should be no changes.
To Reproduce
To reproduce this behaviour I've setup a demo project https://github.com/alexander-jacob/alembic-issue
Error
Versions.
Additional context
public
schema.public
being the default insearch_path
?foo
everything works fine, see branchschema
in example project https://github.com/alexander-jacob/alembic-issue/tree/schemaHave a nice day!
Beta Was this translation helpful? Give feedback.
All reactions