Issues

Issue #2729 new

metadata.create_all do not create Enum in postgre ARRAY

Anonymous created an issue

metadata.create_all do not create work_place_roles if Enum in sqlalchemy.dialects.postgresql.ARRAY

class WorkPlacement(Base):
    __tablename__ = 'work_placement'

    roles = Column(ARRAY(Enum('manager', 'place_admin', 'carwash_admin',
                                      'parking_admin', 'service_admin', 'tire_admin',
                                      'mechanic', 'carwasher', 'tire_mechanic', name="work_place_roles")))

i need do so:

class WorkPlacement(Base):
    __tablename__ = 'work_placement'


    tmp_role = Column(Enum('manager', 'place_admin', 'carwash_admin',
                                      'parking_admin', 'service_admin', 'tire_admin',
                                      'mechanic', 'carwasher', 'tire_mechanic', name="work_place_roles"))
    roles = Column(ARRAY(Enum(name="work_place_roles")))

Comments (4)

  1. Mike Bayer repo owner

    good catch. Here is a better workaround for now:

    from sqlalchemy import event
    
    Base = declarative_base()
    
    enum = Enum('manager', 'place_admin', 'carwash_admin',
                                  'parking_admin', 'service_admin', 'tire_admin',
                                  'mechanic', 'carwasher', 'tire_mechanic', name="work_place_roles")
    class WorkPlacement(Base):
        __tablename__ = 'work_placement'
        id = Column(Integer, primary_key=True)
        roles = Column(ARRAY(enum))
    
    @event.listens_for(Base.metadata, "before_create")
    def _create_enum(metadata, conn, **kw):
        enum.create(conn, checkfirst=True)
    
  2. Log in to comment