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
Autogenerate erroneously considers tables belonging to the default schema to be newly added. #170
Comments
Michael Bayer (@zzzeek) wrote: can you please be more specific as to what the search_path is set to, some samples of tables that are actually in the database and then some examples of exactly how the Table/MetaData is specific on the Python side. SQLAlchemy's "ignore the schema" use case should only apply to the case when we reflect a constraint, and the constraint points to another schema that is also in the search path. 0.9.2 will also provide a new flag ignore_schema_name=False to suit the use case where the user wants to have a complex search_path but still wants explicit schema names on Table objects. |
Michael Bayer (@zzzeek) wrote: also note, just setting your search_path to "public", if even just for within env.py on the Connection used by autogenerate, should clear this up, assuming this is the usual issue of search_path names getting in the way. |
Ben Beanfield (@benbeanfield) wrote: Hi Mike, Yep, changing the search_path to "public" does work, because It appears to me that the code assumes that tables in the metadata that are associated with the default schema will not have an explicit schema configured via (for example) This would explain why it replaces the default schema with None in This appears to be intended to handle the case where users do not specify an explicit schema for their tables, but this fails where users specify an explicit schema for tables which are associated with their default schema. Pseudo example with a existing database which contains tables "foo.car" and "bar.truck", and with a search path=foo:
|
Michael Bayer (@zzzeek) wrote:
that is the case, yup. the schema arg on Table is specifically for those tables that require the "schema." prefix in order to be correctly identified. Note that "schema name" in most databases is a much simpler concept than that of Postgresql.
because again, the assumption is, you only use "schema" to refer to a Table that you specifically want to refer to as in an "other" schema. not the "base" schema.
pretty much. why do you have "schema" set on Table objects that are known to be accessible via the single schema in your search_path? (or alternatively, why is that your search_path? ) |
Changes by Michael Bayer (@zzzeek):
|
Ben Beanfield (@benbeanfield) wrote: That did it. Thank you. |
Migrated issue, originally created by Ben Beanfield (@benbeanfield)
In
alembic.autogenerate.api._produce_net_changes()
, the inspected default schema name is replaced with "None", however if some tables inmetadata_table_names
are explicitly associated with the default schema "foo" - such as with__table_args__ = { 'schema': 'foo' }
- then these will be erroneously considered as new tables when compared withconn_table_names
in_compare_tables()
because "None" will not match "foo".Relevant code snippet:
This will eventually result in this error:
I've temporarily worked around this by changing including:
connection.dialect.default_schema_name = 'public'
in env.py. This works because my default schema is not 'public' and none of my relations are in the 'public' schema.Environment:
Alembic 0.6.2
SQLAlchemy 0.9.1
Postgresql 9.2.6
Configuration: include_schemas=True
The text was updated successfully, but these errors were encountered: