[Sqlalchemy-tickets] Issue #3819: Enum creation doesn't respect metadata schema setting (zzzeek/sql
Brought to you by:
zzzeek
From: tomkcook <iss...@bi...> - 2016-10-06 12:47:09
|
New issue 3819: Enum creation doesn't respect metadata schema setting https://bitbucket.org/zzzeek/sqlalchemy/issues/3819/enum-creation-doesnt-respect-metadata tomkcook: Sample code: ``` #!python from sqlalchemy import create_engine, Column, Enum, Integer, event from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker from sqlalchemy.schema import DDL db = declarative_base() db.metadata.schema = 'test' engine = create_engine('postgresql://tkcook:tkcook@localhost/tkcook') import enum event.listen(db.metadata, 'before_create', DDL('create schema if not exists test')) class Phase(enum.Enum): one = 'one' two = 'two' class Test(db): __tablename__ = 'test_t' id = Column(Integer, primary_key=True) phase = Column(Enum(Phase, name='phase')) db.metadata.create_all(engine) t = Test(id = 1, phase = Phase.one) session = sessionmaker(bind=engine)() session.add(t) session.commit() ``` Expected result: Schema `test` contains a table called `test_t` and a type called `phase`. Actual result: Schema `test` contains a table called `test_t` but the type `phase` is created in schema `public`. |