On 6/11/14, 4:54 PM, Stefan Urbanek wrote: > Hi, > > I'm trying to create tables using alembic with custom engine/metadata > objects, already configured by our other library. I want all the > tables to default to one schema – schema specified in the metadata. I > have the original code: > > context.configure( > connection=connection, > target_metadata=target_metadata > ) > > where the target_metadata is our metadata object set-up somewhere else > and has properly set schema value. > > Alembic still creates the table in the "public" schema (PostgreSQL) on > 'upgrade' > > My goal in other words: I want all tables to default to specific > schema implicitly, use explicit schema= in op.create_table only when > really needed. > > What I am doing wrong?
there's no implication that the "schema" that's set inside of target_metadata has any connection to the schema that is used by op.create_table() or any other directives. As documented, target_metadata is only involved with the autogeneration process, and additionally that the "naming_convention" aspect of it is consulted for some operations, if present. "schema" currently is not. for directives like op.create_table(), there's no implicit behavior. If you want op.create_table to have some default schema, you'd need to write a helper function: def create_table(*args, **kw): metadata = op.migration_context.opts['target_metadata'] kw.setdefault("schema", metadata.schema) return op.create_table(*args, **kw) now, this is not to say that this cant be added as a feature. I'd accept a PR that implements "default_schema" as an argument to EnvironmentContext.configure() and propagates it through MigrationContext into Operations. -- You received this message because you are subscribed to the Google Groups "sqlalchemy-alembic" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy-alembic+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.