I have a Flask model:
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)
And I've created an migration with flask-migrate (db is 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')
)
Migration was created successfuly, but when I want to upgrade, this error rising:
TypeError: <flask_script.commands.Command object at 0x7fada1e973d0>: __init__() got an unexpected keyword argument 'length'
Can somebody explain the problem?
As the error says, ChoiceType
does not have an init argument called length
:
http://sqlalchemy-utils.readthedocs.org/en/latest/data_types.html#module-sqlalchemy_utils.types.choice
You can remove it and use
sqlalchemy_utils.types.choice.ChoiceType(User.ROLES)
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With