Enum ChoiceType column results in error
See original GitHub issueHowdy folks!
The following code produces TypeError: 'MyEnum' object is not iterable
, but should work. Note that this is also involves package sqlalchemy_utils
from enum import Enum
class MyEnum(Enum):
foo = 1
bar = 2
class MyModel(Base):
id = Column(sa.Integer, primary_key=True)
name = Column(sa.Unicode(255))
type = Column(ChoiceType(MyEnum, impl=Integer()))
class MyObject(SQLAlchemyObjectType):
class Meta:
model = MyModel
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top Results From Across the Web
How to use Enum with SQLAlchemy and Alembic?
First, import the Python enum, the SQLAlchemy Enum, and your SQLAlchemy declarative base wherever you're going to declare your custom SQLAlchemy ...
Read more >Solved: Disable Button on Data verse Choice column - Expec...
One of the columns is of choice type, called TaskType. I have a button outside of the ... but I'm getting the error,...
Read more >EnumType Field (Symfony Docs)
A multi-purpose field used to allow the user to "choose" one or more options defined in a PHP enumeration. It extends the ChoiceType...
Read more >MySQL 8.0 Reference Manual :: 11.3.5 The ENUM Type
If strict SQL mode is enabled, attempts to insert invalid ENUM values result in an error. If an ENUM column is declared to...
Read more >How to Create Django Like Choices Field in Flask SQLAlchemy
Save yourself all that error handling and enforce at the database level what values are allowed in a field. Python · Flask ·...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sure, but that defeats the automagical nature of using
SQLAlchemyObjectType
along withmodel = MyModel
😄. Part of the beauty of this library is that I don’t have to specify the Schema fields, because they are deduced from the SQLAlchemy model.There’s also the fact that using
sqlalchemy.Enum(MyEnum)
works butsqlalchemy_utils.ChoiceType(MyEnum)
doesn’t 😦.@kurtwiersma if you’re still up for that, feel free to go ahead. It’s probably best to create a new branch for the old release. Would appreciate the effort!