# How to enable json/jsonb type from django.contrib.postgres installation

**URL:** <https://forum.djangoproject.com/t/how-to-enable-json-jsonb-type-from-django-contrib-postgres-installation/4721>\
**Category:** Using Django\
**Created:** [October 9, 2020, 6:21pm UTC](https://forum.djangoproject.com/t/how-to-enable-json-jsonb-type-from-django-contrib-postgres-installation/4721 "2020-10-09T18:21:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![technqvi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/technqvi/32/1851_2.png) [@technqvi](https://forum.djangoproject.com/u/technqvi)\
**Post date:** [October 9, 2020, 6:21pm UTC](https://forum.djangoproject.com/t/how-to-enable-json-jsonb-type-from-django-contrib-postgres-installation/4721/1 "2020-10-09T18:21:02Z")

</div>

Hi

I use the existing Postgres database for my project.  
Some tables in my database need to use JSON / jsonb field.

I read how to inspect existing database along with adding an extra feature especially data type for Postgres as 3 links below  
[https://docs.djangoproject.com/en/3.1/howto/legacy-databases/](https://docs.djangoproject.com/en/3.1/howto/legacy-databases/)

[https://docs.djangoproject.com/en/3.1/ref/django-admin/#postgresql](https://docs.djangoproject.com/en/3.1/ref/django-admin/#postgresql)

[https://docs.djangoproject.com/en/3.1/ref/contrib/postgres/#module-django.contrib.postgres](https://docs.djangoproject.com/en/3.1/ref/contrib/postgres/#module-django.contrib.postgres)

as my understanding, the article recommends me to install ‘django.contrib.postgres’ in INSTALLED\_APPS in settings.py so I suppose that it is a build-in package from Django but we must manually install in settings.py  
and then run python manage.py inspectdb

once I ran the command to inspect the existing database, it works well _but the column “additional\_info” that it is JSON field in the database still is models.TextField ( This field type is a guess) as the figure below._

 ![inspectDB1](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/b/b1ceca3876b1c0b67cfd454c4015843efef88027.png)

**1. how to fix this problem? OR ELSE do I have to install any addtional package ?**  
**As I find out, there are a lot as below for extra feature in Posgres.**  
[https://pypi.org/project/django-jsonfield-backport/](https://pypi.org/project/django-jsonfield-backport/)  
[https://pypi.org/project/django-postgres-extensions/](https://pypi.org/project/django-postgres-extensions/)  
[https://pypi.org/project/django-contrib-postgres/](https://pypi.org/project/django-contrib-postgres/)

_2. How to select only some tables in the existing database as desired to inspect in order to create models.py (not all tables in database)_

Thank you  
Trong

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [October 10, 2020, 12:05am UTC](https://forum.djangoproject.com/t/how-to-enable-json-jsonb-type-from-django-contrib-postgres-installation/4721/2 "2020-10-10T00:05:56Z")

</div>

1. InspectDb is not a 100% solution. It’s [known and documented](https://docs.djangoproject.com/en/3.1/ref/django-admin/#inspectdb) that you are going to need to manually adjust the models it creates. There is no problem to fix. For those fields that are misidentified, just edit the generated model to make it the correct field type.

2. See the referenced documentation from above for identifying which tables to examine.

Ken

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [October 10, 2020, 9:29am UTC](https://forum.djangoproject.com/t/how-to-enable-json-jsonb-type-from-django-contrib-postgres-installation/4721/3 "2020-10-10T09:29:26Z")

</div>

This might be a regression in Django 3.1. Previously it seems that inspectdb could detect jsonb columns as JSONFields — see [ticket #30476](https://code.djangoproject.com/ticket/30476), which tried to add the same for “json” (no b) columns. If you try on Django 3.0, do you get `JSONField`s? In which case we might want to add this back on 3.1, for all DB’s.

---

<div class="post-metadata">

**Author:** ![technqvi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/technqvi/32/1851_2.png) [@technqvi](https://forum.djangoproject.com/u/technqvi)\
**Post date:** [October 12, 2020, 8:19am UTC](https://forum.djangoproject.com/t/how-to-enable-json-jsonb-type-from-django-contrib-postgres-installation/4721/4 "2020-10-12T08:19:09Z")

</div>

Hi,  
as I suggest above.

I summarize as my understanding like below.  
**1.i can put django.contrib.postgres in INSTALLED\_APPS without any additoinal pip installation. Right?**

\*\*2. after runing inspectdb then I can manually adjust the models like json datatype instead of text \*\*  
**3.run makemigrations and migrate to update schema to database**

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [October 12, 2020, 1:14pm UTC](https://forum.djangoproject.com/t/how-to-enable-json-jsonb-type-from-django-contrib-postgres-installation/4721/5 "2020-10-12T13:14:15Z")

</div>

1. Yes. All the django.contrib packages are part of the Django installation. However, you do also need the psycopg2 package. (I typically use psycopg2-binary.)
2. Yes. And, there may be other changes you may want or need to make as well.
3. Yes. Keep in mind that inspectdb marks all models as manage=False, which means that makemigrations / migrate aren’t going to affect those tables.

Ken

---

<div class="post-metadata">

**Author:** ![technqvi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/technqvi/32/1851_2.png) [@technqvi](https://forum.djangoproject.com/u/technqvi)\
**Post date:** [October 12, 2020, 4:38pm UTC](https://forum.djangoproject.com/t/how-to-enable-json-jsonb-type-from-django-contrib-postgres-installation/4721/6 "2020-10-12T16:38:54Z")

</div>

> [@KenWhitesell](#):
>
> I typically use psycopg2-binary

I already installed psycopg2 , is it ok?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [October 12, 2020, 4:40pm UTC](https://forum.djangoproject.com/t/how-to-enable-json-jsonb-type-from-django-contrib-postgres-installation/4721/7 "2020-10-12T16:40:55Z")

</div>

Sure is - your choice either way. I was just mentioning which one I use. There’s no “right” or “wrong” answer in this case.

---

<div class="post-metadata">

**Author:** ![technqvi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/technqvi/32/1851_2.png) [@technqvi](https://forum.djangoproject.com/u/technqvi)\
**Post date:** [October 12, 2020, 5:22pm UTC](https://forum.djangoproject.com/t/how-to-enable-json-jsonb-type-from-django-contrib-postgres-installation/4721/8 "2020-10-12T17:22:50Z")

</div>

well done.  
I really appreciate your support.
