﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30476	"Add introspection of ""json"" (like ""jsonb"") data type as JSONField on PostgreSQL."	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.

[https://docs.djangoproject.com/en/2.2/ref/contrib/postgres/fields/#django.contrib.postgres.fields.JSONField 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 [https://github.com/django/django/blob/2.2/django/contrib/postgres/apps.py#L49 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:

{{{#!sql
SELECT oid, typname
FROM pg_catalog.pg_type
WHERE typname='json';
}}}

Also happy to check other database versions if needed.
"	New feature	closed	contrib.postgres	dev	Normal	wontfix	inspectdb, JSONField, json, jsonb		Unreviewed	0	0	0	0	0	0
