由于sqlalchemy中没有提供choice方法,所以借助SQLAlchemy-Utils组件提供的choice方法。
安装:
pip3 install sqlalchemy_utils
示例:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column from sqlalchemy import Integer, String from sqlalchemy import create_engine from sqlalchemy_utils import ChoiceType Base = declarative_base() class UserInfo(Base): __tablename__ = "