alembic
alembic copied to clipboard
postgres ExcludeConstraint not generating correctly
Describe the bug
Using the postgres dialect the ExcludeConstraint drops the ops
when creating the migration file
Expected behavior The constraint should be transferred to the migration file
To Reproduce Using the following model
class Network(Base):
__tablename__ = 'network'
network_id: uuid.UUID = sqlalchemy.Column(pg.UUID(as_uuid=True), primary_key=True, default=uuid.uuid4,
server_default=sql.func.gen_random_uuid(), nullable=False)
networka: str = sqlalchemy.Column("networka", pg.INET)
__table_args__ = (
pg.ExcludeConstraint(('networka', '&&'), using="gist", ops={'networka': 'inet_ops'}),
)
run the command alembic revision --autogenerate
the output is generated for that model
op.create_table('network',
sa.Column('network_id', postgresql.UUID(as_uuid=True), server_default=sa.text('gen_random_uuid()'), nullable=False),
sa.Column('networka', postgresql.INET(), nullable=True),
postgresql.ExcludeConstraint((sa.column('networka'), '&&'), using='gist'),
sa.PrimaryKeyConstraint('network_id'),
)
The postgresql.ExcludeConstraint
part has dropped the ops
, it should have rendered
postgresql.ExcludeConstraint((sa.column('networka'), '&&'), using='gist', ops={'networka': 'inet_ops'}),
Error No errors occur after generation, but Postgres will fail to create a table when you attempt to upgrade.
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedObject) data type inet has no default operator class for access method "gist"
HINT: You must specify an operator class for the index or define a default operator class for the data type.
Versions.
- OS: Linux
- Python: 3.9
- Alembic: 1.7.4
- SQLAlchemy: 1.4.20
- Database: Postgres 13
Additional context Not a show-stopper for me, I just needed to manually add in the code.
Have a nice day!
For reference this is the PR of the addition https://github.com/sqlalchemy/sqlalchemy/pull/5700
we dont have reflection for this yet but a straight autogen from the model should be able to work