weixin_39890652 2020-11-30 11:37
浏览 1

autogenerate does not detect existing tables when inside Postgresql schema

Migrated issue, originally created by kalterkrieg ()

Hello,

Even with include_schema=True, alembic does not detect the tables inside a Postgresql schema.

I have the following model :


# imports

Base = declarative_base(cls=DeferredReflection)

__all__ = ['IdbRelease']

idb_source_enum = ['PALISADE', 'MIB', 'SRDB']

class IdbRelease(Base):

    id_idb_release = Column(INTEGER(), primary_key=True)
    idb_version = Column(String(32))
    idb_source = Column(ENUM(*idb_source_enum, name='idb_source_type'))

    __tablename__ = 'idb_release'
    __table_args__ = (
        UniqueConstraint('idb_version', 'idb_source'),
        {'schema': 'idb'}
    )

I create the schema idb with postgresql, and then run alembic revision --autogenerate, it works as expected.


INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.autogenerate.compare] Detected added table 'idb.idb_release'
  Generating /home/kalterkrieg/Documents/ROC/test_schema/alembic/versions/bae007b864b3_.py ... done

However when I run alembic revision --autogenerate a second time, I have the exact same message : Detected added table 'idb.idb_release'

In my env.py :


def run_migrations_online():
    connectable = engine_from_config(
        config.get_section(config.config_ini_section),
        prefix='sqlalchemy.',
        poolclass=pool.NullPool)


    from sqlalchemy.engine import reflection
    insp = reflection.Inspector.from_engine(connectable)
    print(insp.get_schema_names())


    with connectable.connect() as connection:
        context.configure(
            connection=connection,
            target_metadata=target_metadata,
            include_schema=True
        )

get_schema_names() function returns


['idb', 'information_schema', 'public']

The include_schema=True argument should make alembic look into the idb schema if the table idb_release exists, but it does not seem to work.

Everything works well when I remove the line {'schema': 'idb'} in my model

I am using alembic==0.9.9 and SQLAlchemy==1.2.6

该提问来源于开源项目:sqlalchemy/alembic

  • 写回答

5条回答 默认 最新

  • weixin_39890652 2020-11-30 11:37
    关注

    Michael Bayer () wrote:

    did you mean to use include_schemas ?

    评论

报告相同问题?