shr*_*oud 5 python sqlalchemy alembic
我有以下模型:
class Table(Base):
__tablename__ = 'table'
__table_args__ = (
Index('bar_baz_idx', 'bar', 'baz', unique=True,
postgresql_where='foo IS NULL AND bar IS NOT NULL '
'AND baz IS NOT NULL'),
{'schema': 'custom_schema'},
)
foo = Column(String(80), nullable=True)
bar = Column(String(80), nullable=True)
baz = Column(String(80), nullable=True)
Run Code Online (Sandbox Code Playgroud)
当我自动生成 Alembic 迁移时,它会产生以下升级功能:
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('table',
sa.Column('foo', sa.String(length=80), nullable=True),
sa.Column('bar', sa.String(length=80), nullable=True),
sa.Column('baz', sa.String(length=80), nullable=True),
sa.Column('fxt', sa.String(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint('id'),
schema='custom_schema'
)
op.create_index('bar_baz_idx', 'table', ['bar', 'baz'], unique=True, schema='custom_schema', postgresql_where='foo IS NULL AND bar IS NOT NULL AND baz IS NOT NULL')
Run Code Online (Sandbox Code Playgroud)
但是,这失败了(在 Alembic 0.9.6 上),回溯如下:
File "/Users/username/.virtualenvs/myproj/lib/python3.4/site-packages/SQLAlchemy-1.1.15-py3.4-macosx-10.6-intel.egg/sqlalchemy/dialects/postgresql/base.py", line 1727, in visit_create_index
literal_binds=True)
File "/Users/username/.virtualenvs/myproj/lib/python3.4/site-packages/SQLAlchemy-1.1.15-py3.4-macosx-10.6-intel.egg/sqlalchemy/sql/compiler.py", line 242, in process
return obj._compiler_dispatch(self, **kwargs)
AttributeError: 'str' object has no attribute '_compiler_dispatch'
Run Code Online (Sandbox Code Playgroud)
有什么明显的我在这里做错了吗?没有postgresql_where参数它似乎工作正常。