# Migrating data.json to Django's ORM

**URL:** <https://forum.djangoproject.com/t/migrating-data-json-to-djangos-orm/13053>\
**Category:** Getting Started\
**Created:** [April 7, 2022, 8:10pm UTC](https://forum.djangoproject.com/t/migrating-data-json-to-djangos-orm/13053 "2022-04-07T20:10:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![humblehagfish](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/humblehagfish/32/8057_2.png) [@humblehagfish](https://forum.djangoproject.com/u/humblehagfish)\
**Post date:** [April 7, 2022, 8:10pm UTC](https://forum.djangoproject.com/t/migrating-data-json-to-djangos-orm/13053/1 "2022-04-07T20:10:33Z")

</div>

I have a project created with poetry: `poetry new little-bits-of-buddha`. It was a very basic Flask app that returned a random bit of JSON from a `data.json` file. Now I want to ingest the JSON into a database. I picked Django for its ORM and because there was a big community behind it and a great book, “Django for Beginners”.

I created the django project with `django-admin startproject little_bits_of_buddha .`

Here’s what my project looks like after:

```auto
x exa --tree
.
├── little_bits_of_buddha
│ ├── __init__.py
│ ├── app.py
│ ├── asgi.py
│ ├── data.py
│ ├── data.json
│ ├── settings.py
│ ├── shim.py
│ ├── urls.py
│ └── wsgi.py
├── main
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ │ ├── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── manage.py
├── poetry.lock
├── pyproject.toml
├── README.org
└── tests
   ├── __init__.py

```

Now, I want to make my first Django app, which I do from the root project directory like the other commands:  
`python3 manage.py startapp main`

Since my dumb app is so small, we can recreate the entire logic from `python manage.py shell`

```auto
import json
from importlib import resources

with resources.open_text("little_bits_of_buddha", "data.json") as json_file:
  data = json.load(json_file)

from django.db import models

class Collection(models.Model):
    models.JSONField(data)

```

which returns:

```auto
...
    130 if app_config is None:
    131 if not abstract:
--> 132 raise RuntimeError(
    133 "Model class %s.%s doesn't declare an explicit "
    134 "app_label and isn't in an application in "

RuntimeError: Model class __main__.Collection doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

```

If I’m interpreting this correctly, the app isn’t listed in `INSTALLED_APPS` but here it is:

```auto
INSTALLED_APPS = [
    "main.apps.MainConfig",
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
]

```

My tree looks fairly similar to the [mataroa](https://git.sr.ht/~sirodoht/mataroa/tree/master) project.

My question:

- Can I import an entire nested JSON object into a Django model like I’ve demonstrated and have the ORM create it in the corresponding Postgres database? I want to preserve the [data.json](https://gist.github.com/worldofgeese/0921df46c5463e94445c3f279bb6265e) file as the final arbiter of truth.

---

<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:** [April 8, 2022, 7:02pm UTC](https://forum.djangoproject.com/t/migrating-data-json-to-djangos-orm/13053/2 "2022-04-08T19:02:41Z")

</div>

> [@humblehagfish](#):
>
> Can I import an entire nested JSON object into a Django model like I’ve demonstrated and have the ORM create it in the corresponding Postgres database?

The short and direct answer is “Yes”.

You have numerous ways to approach this. (For example, are you looking to bring the entire content in as a single instance of a model? Or are you looking to separate it into separate objects for different instances? Are you looking to copy data into individual columns?)

But you probably want to ensure you’re worked your way through enough of the book to understand how models and views work before trying to take this step.
