sqlalchemy enum AttributeError: 'list' object has no attribute 'replace'
2016-05-11 16:58
507 查看
在column中使用Enum:
在stackoverflower上找了一下,发现这么用可以:
class User(Base): __tablename__ = 'user' USER_ROLE_CHOICES = ['SU', 'GA', 'CU'] id = Column(Integer, primary_key=True) password = Column(String(128)) last_login = Column(DateTime) is_superuser = Column(Boolean) username = Column(String(30), unique=True) first_name = Column(String(30)) last_name = Column(String(30)) email = Column(String(30)) is_staff = Column(Boolean) is_active = Column(Boolean) date_joined = Column(DateTime) role = Column(Enum(USER_ROLE_CHOICES)) #AttributeError: 'list' object has no attribute 'replace' group = relationship('UserGroup', secondary=user_usergroup, backref='user')
在stackoverflower上找了一下,发现这么用可以:
role = Column(Enum('SU', 'GA', 'CU'))
相关文章推荐
- JavaScriptCore和Objective-C
- Object-c 开源类库
- Objective-c之浅复制与深复制
- Bit masking for introspection of Objective-C object pointer is strongly discounraged
- object-c中Foundation框架-日期和时间-----------包含定时器
- [论文阅读]HyperNet: Towards Accurate Region Proposal Generation and Joint Object Detection
- relocation R_X86_64_32 against XXXXX can not be used when making a shared object;recompile with -fPI
- object-c中Foundation框架-NSString与NSMutableString
- iOS基础:深入理解Objective-c中@class的含义
- iOS基础:深入理解Objective-c中@class的含义
- object-c中的@try
- object-c-协议-protocol
- Objective-C的Block
- 浅析C# 中object sender与EventArgs e (转)
- 文献笔记 You Only Look Once:Unified, Real-Time Object Detection
- 理解 Objective-C Runtime
- Objective-C与Runtime的那点事儿消息机制
- object-c中扩展--extension
- Objective-C与Runtime的那点事儿消息机制
- 理解 Objective-C Runtime