Opened 6 years ago

Last modified 6 years ago

#30476 closed New feature

Add detection for PostgreSQL json field, aside from the already existing detection for jsonb field, using inspectdb — at Version 1

Reported by: Héctor Pablos Owned by:
Component: contrib.postgres Version: dev
Severity: Normal Keywords: inspectdb, JSONField, json, jsonb
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Héctor Pablos)

Right now, the inspectdb command, when the django.contrib.postgres app is added to INSTALLED_APPS in the settings, is able to detect jsonb fields and generate a model with the right django.contrib.postgres.fields.JSONField, but that's not the case for simple json fields.

The documentation states that the JSONField uses internally a PostgreSQL jsonb field, but I wonder if normal json fields could also be detected as a JSONField, as they can perfectly work for unmanaged models.

I'm happy to do a patch for this if it's considered necessary, adding an additional key to the ones provided by the contrib.postgres module inside the data_types_reverse dict with the following information:

114:  'django.contrib.postgres.fields.JSONField',

And the documentation and tests considered being necessary.

The id 114 is the OID of the json data type in PostgreSQL, at least in its 11.1 version. You can check this by executing the following query:

SELECT oid, typname
FROM pg_catalog.pg_type
WHERE typname='json';

Also happy to check other database versions if needed.

Change History (1)

comment:1 by Héctor Pablos, 6 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top