0

I'm trying to use ExcludeConstraint in my SQLAlchemy model:

class MyModel(db.Model):

    some_string = Column(Unicode(length=20), nullable=True)
    some_type = Column('some_type', Integer, nullable=False)

    __table_args__ = (
        ExcludeConstraint(
            ('some_string', '='), ('some_type', '<>'),
            name='my_constraint'
        ),
    )

But I've got an exception, when I run my test suite using temporary db:

E       ProgrammingError: (psycopg2.ProgrammingError) data type character varying has no default operator class for access method "gist"
E       HINT:  You must specify an operator class for the index or define a default operator class for the data type.

Which means, that I have to execute CREATE EXTENTION btree_gist before creating table. Can I do it somehow using SQLAlchemy? Any smarter way then manual SQL execute before creating temporary database for test suite?

Andrii Skaliuk
  • 428
  • 1
  • 6
  • 14
  • 1
    Tie your DDL to *before_create* of `MyModel.__table__`: http://docs.sqlalchemy.org/en/latest/core/events.html#sqlalchemy.events.DDLEvents.before_create – Ilja Everilä Jan 18 '17 at 20:10
  • Also http://stackoverflow.com/questions/16629037/how-do-i-get-alembic-to-emit-custom-ddl-on-after-create – Ilja Everilä Jan 18 '17 at 20:14

0 Answers0