I have the following model:
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)
Which produces the following upgrade function, when I autogenerate an Alembic migration:
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')
However, this fails (on Alembic 0.9.6) with the following traceback:
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'
Is there something obvious that I'm doing wrong here? It seems to work fine without the postgresql_where argument.