Opened 9 years ago
Last modified 8 months ago
#24928 new New feature
Add UUIDField, RangeField, JSONField, etc to database introspection
Reported by: | Markus Holtermann | Owned by: | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Ülgen Sarıkavak | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
django.db.backends.postgresql_psycopg2.introspection.DatabaseIntrospection.data_types_reverse does not handle UUIDField and other core or contrib.postgres specific fields. And neither does any of the other backends.
Change History (15)
comment:1 by , 9 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Bug → New feature |
comment:2 by , 9 years ago
IMHO, introspection should show the most accurate type, independently of the presence of contrib.postgres
in the INSTALLED_APPS.
comment:3 by , 9 years ago
Claude, the issue in my mind is adding contrib references to django/db/backends/postgresql_psycopg2/introspection.py
. If we allow contrib.postgres
to play by special rules, that's not very friendly to third-party apps that might wish to add introspection for their own fields. But you have more experience in this area than I do, so please give your thoughts if you had ideas on how this should work.
comment:4 by , 9 years ago
For me, this is not special rules, it's the rule "Django tries its best to introspect the database fields". If anyone want to provide contrib.mysql or contrib.oracle with custom fields, she's welcome to do so and we'll also be able to improve introspection for those backends.
Currently Django outputs models.TextField(blank=True, null=True) # This field type is a guess.
for fields it doesn't know. Even if some field type is not implemented by Django models, we could imagine that we provide better hints (provided the type code is known), and point to popular third-party packages which implements those fields, inside comments.
comment:5 by , 9 years ago
What I envisioned for my proposal is a way for any app to contribute a mapping to a particular database backend's DatabaseIntrospection.data_types_reverse
dictionary. I guess it might work something like south.modelsinspector.add_introspection_rules
does, although I haven't looked at the implementation of that. Of course there's also the need to add the appropriate import in the models file that inspectdb generates since all fields won't be in django.db.models
anymore.
comment:6 by , 8 years ago
Summary: | Add UUIDField, RangeField, etc to database introspection → Add UUIDField, RangeField, JSONField, etc to database introspection |
---|
comment:7 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:8 by , 8 years ago
As UUIDField
is a bit different (available in all backends with different implementation), I created a pull request just for that field.
A separate pull request will be proposed for other PostgreSQL-specific fields.
comment:9 by , 8 years ago
Has patch: | set |
---|
The "final" pull request, including the commit linked from the previous comment and the fix for #25454.
comment:13 by , 7 years ago
Patch needs improvement: | set |
---|
HStoreField and ArrayField support still missing.
comment:14 by , 3 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:15 by , 8 months ago
Cc: | added |
---|
There's an interesting question about how contrib.postgres can "contribute" introspection rules to the postgres backend. Maybe the contrib.postgres fields should be handled in a separate ticket.