django-enumfield
django-enumfield copied to clipboard
Use native enums if the database supports them
All major databases that Django support already supports enums at the database level.
You can also implement enums in SQLite using CHECK.
Is there a good way to hook into south and django migrations framework in order to make this field use their native database type?
Good idea, it would be interesting to try it out. It could be as simple as overriding db_type
on the EnumField
-class.
https://docs.djangoproject.com/en/dev/howto/custom-model-fields/#custom-database-types
In postgres you have to run CREATE TYPE first so a migration is required. On the other databases it should be a matter of overrriding db_type.
Any progress on this?
I'm gonna try to implement it when I'm in London. The next Django sprint will take place there.
"2. Changing the member list of ENUM columns is very expensive." http://komlenic.com/244/8-reasons-why-mysqls-enum-data-type-is-evil/
I'm looking at a different path, which would have enum values in a classic lookup table with foreign key instead. The table has auto_id, enum_value, enum_label , and i'm trying to come up with a reasonably safe sync method that updates existing databases with new model code from the enum classes as needed.
django-enumfield is cool as its implemented, but i really want to enforce referential integrity at the db level, and also have my database make sense to someone who has never looked at django/python at all.
If someone has done this already, i'd appreciate a pointer.
Upstream Django issue: #24342: Add EnumField model/form fields
Related implementation: https://github.com/ashleywaite/django-more/tree/master/django_enum
is this a stale issue? looks like the issue is dormant on the upstream django tickets board. it would be nice if this library can support it.
Happy to open a PR if it would be considered