5monkeys / django-enumfield

Custom Django field for using enumerations of named constants
MIT License
204 stars 46 forks source link

Use native enums if the database supports them #18

Open thedrow opened 9 years ago

thedrow commented 9 years ago

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?

hannseman commented 9 years ago

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

thedrow commented 9 years ago

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.

AncientSwordRage commented 9 years ago

Any progress on this?

thedrow commented 9 years ago

I'm gonna try to implement it when I'm in London. The next Django sprint will take place there.

kjagiello commented 9 years ago

"2. Changing the member list of ENUM columns is very expensive." http://komlenic.com/244/8-reasons-why-mysqls-enum-data-type-is-evil/

kaidokert commented 9 years ago

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.

PiDelport commented 6 years ago

Upstream Django issue: #24342: Add EnumField model/form fields

Related implementation: https://github.com/ashleywaite/django-more/tree/master/django_enum

HaddadJoe commented 1 year ago

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