我有以下型号:
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)
当我自动生成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')
然而,这次失败(在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'
我有什么明显的错误吗?没有postgresql_where
参数,它似乎工作正常。