Hello.
No matter how I tried to use sqlalchemy_utils.types.choice.ChoiceType in SQLAlchemy models, nothing happened.
If I do, as indicated in the documentation:
class User(Base): TYPES = [ (u'admin', u'Admin'), (u'regular-user', u'Regular user') ] __tablename__ = 'user' id = sa.Column(sa.Integer, primary_key=True) name = sa.Column(sa.Unicode(255)) type = sa.Column(ChoiceType(TYPES)) then, in the migration version the following line is formed:
sa.Column('type', sqlalchemy_utils.types.choice.ChoiceType(length=255), nullable=True), and the error is:
TypeError: <flask_script.commands.Command object at 0x7f90349e0dd8>: __init__() got an unexpected keyword argument 'length' here it is advised to do this: sqlalchemy_utils.types.choice.ChoiceType(User.ROLES)
but in this case, swears on import User, because The migration version is 'user'.
recommend doing so:
from sqlalchemy import Column, Enum from .db import Base class MyModel(Base): STATUS_CHOICES = ( ('published', 'Published'), ('hidden', 'Hidden'), ) STATUSES = tuple(c[0] for c in STATUS_CHOICES) status = Column( ChoiceType(impl=Enum(*STATUSES, name='mymodel_status'), choices=STATUS_CHOICES), default='published', nullable=False ) and this is more likely to be true, since such a string is formed in the migration version:
sa.Column('type', sqlalchemy_utils.types.choice.ChoiceType(('google adwords', 'yandex direct')), nullable=False) ,
but in this case I get this error:
ValueError: dictionary update sequence element #0 has length 14; 2 is required I use SQLite3 on the maiden. Problems may be related to this, but nowhere in the documentation is it stated that this may cause problems.
Of course, you can refer to the table in which the necessary types will be indicated, as I did before, but I don’t really like this way. All the same, I would like to use sqlalchemy_utils to the full.
If someone came across and knows how to solve this problem, I will be extremely grateful for any help or tip.