Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use native enums if the database supports them #19

Open
bckohan opened this issue Jan 31, 2023 · 4 comments
Open

Use native enums if the database supports them #19

bckohan opened this issue Jan 31, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@bckohan
Copy link
Owner

bckohan commented Jan 31, 2023

Upstream: https://code.djangoproject.com/ticket/24342

Are there any advantages to doing this?

@bckohan bckohan self-assigned this Jan 31, 2023
@bckohan bckohan added the question Further information is requested label Mar 29, 2023
@bckohan
Copy link
Owner Author

bckohan commented Jul 16, 2023

Enums are supported by postgres, mysql, mariadb and oracle. The only Django supported RDBMS that does not support them as native types is SQLite.

They do not offer much advantage over django-enum's implementation using check constraints but one solid reason to support them is to support inspectdb.

@bckohan
Copy link
Owner Author

bckohan commented Jul 16, 2023

MYSQL, Mariadb and Oracle all support enum creation inline with table creation. Postgres requires the Enum type to be created before the table, i.e. CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');. Its unclear to me how you might generate migrations that do this without monkey patching Django internals.

@bckohan
Copy link
Owner Author

bckohan commented Jul 16, 2023

I would like to support native enum types in the future. Kicking this can down the road to after the 2.0 release.

My current thinking is to add a native toggle as a kwarg to EnumField:

enum_field = EnumField(EnumClass, native=True)

This would resolve to a NativeEnumField type that works on connections other than sqlite and uses the names of the EnumClass as the internal database Enum types. Supporting this on mariadb, mysqldb and oracle seems trivial - postgres is more complicated.

@bckohan bckohan added help wanted Extra attention is needed enhancement New feature or request and removed question Further information is requested labels Jul 26, 2023
@bckohan
Copy link
Owner Author

bckohan commented Jul 26, 2023

TBD, is there a way to create a 'CREATE TYPE' migration sql statement on postgres without monkey-patching Django internals? Similarly is there a way to support inspect db without monkey patching Django internals? If monkeypatching is required, what is the least brittle, and least invasive way to do it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant