class User(db.Model):
ROLE_USER = 0
ROLE_MODERATOR = 1
ROLE_ADMIN = 2
ROLES = [
(ROLE_USER, u'Regular user'),
(ROLE_MODERATOR, u'Moderator'),
(ROLE_ADMIN, u'Admin')
]
id = db.Column(db.Integer, primary_key = True)
login = db.Column(db.String(32), nullable=False, unique=True)
first_name = db.Column(db.String(32))
last_name = db.Column(db.String(32))
role = db.Column(ChoiceType(ROLES), nullable=False)
我用flask-migrate创建了一个迁移(db是Postgresql):
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('login', sa.String(length=32), nullable=False),
sa.Column('first_name', sa.String(length=32), nullable=True),
sa.Column('last_name', sa.String(length=32), nullable=True),
sa.Column('role', sqlalchemy_utils.types.choice.ChoiceType(length=255), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('login')
)
TypeError: <flask_script.commands.Command object at 0x7fada1e973d0>: __init__() got an unexpected keyword argument 'length'
有人能解释一下这个问题吗?
解决方法:
正如错误所说,ChoiceType没有名为length的init参数:
您可以将其删除并使用
sqlalchemy_utils.types.choice.ChoiceType(User.ROLES)
代替.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。