当前位置:   article > 正文

sqlalchemy enum AttributeError: 'list' object has no attribute 'replace'

list' object has no attribute 'replace

在column中使用Enum:

  1. class User(Base):
  2. __tablename__ = 'user'
  3. USER_ROLE_CHOICES = ['SU', 'GA', 'CU']
  4. id = Column(Integer, primary_key=True)
  5. password = Column(String(128))
  6. last_login = Column(DateTime)
  7. is_superuser = Column(Boolean)
  8. username = Column(String(30), unique=True)
  9. first_name = Column(String(30))
  10. last_name = Column(String(30))
  11. email = Column(String(30))
  12. is_staff = Column(Boolean)
  13. is_active = Column(Boolean)
  14. date_joined = Column(DateTime)
  15. role = Column(Enum(USER_ROLE_CHOICES)) #AttributeError: 'list' object has no attribute 'replace'
  16. group = relationship('UserGroup',
  17. secondary=user_usergroup,
  18. backref='user')

在stackoverflower上找了一下,发现这么用可以:

role = Column(Enum('SU', 'GA', 'CU'))


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/766974
推荐阅读
相关标签
  

闽ICP备14008679号