ENUM type in SQLAlchemy with PostgreSQL

前端 未结 4 1997
我寻月下人不归
我寻月下人不归 2020-12-24 07:48

I\'m using SQLAlchemy core with a postgresql database and I would like to add the ENUM type to my table definition. According to the postgresql documentatio

4条回答
  •  醉酒成梦
    2020-12-24 08:50

    You need to import Enum from sqlalchemy and add a name to it. It should work like this:

    from sqlalchemy import Enum
    
    person = Table("user_profile", metadata,
        Column("name", String(20)),
        Column("gender", Enum("female", "male", name="gender_enum", create_type=False))
    );
    

提交回复
热议问题