kadash
kadash

Reputation: 290

Postgres/python django import json dump database

I got json database dump file to import into postgres but this file is not sql file (which I know how to import) it is json file. Its structure looks like this:

[
    {
      "model": "model.name",
      "pk": 1,
      "fields": {
        "version": 1584369114566125,
        "field_a": "something",
        "field_b": "something"
      }
    },
    {
        "model": "model.name",
        "pk": 1,
        "fields": {
            "version": 1584369114566125,
            "field_a": "something",
            "field_b": "something"
        }
    },
    ...
]

I want to import it but I don't know if is there option for importing database in such format and structure without writing sql function? I was trying to find if there is in documentation of pg_dump any option for exporting in json but I didn't find. My guess is also that server is written in django and maybe django has script for exporting/importing database in such file?

Upvotes: 1

Views: 1404

Answers (1)

Selcuk
Selcuk

Reputation: 59184

The format you posted looks like a fixture:

You’ll store this data in a fixtures directory inside your app. [...] You can load data by calling manage.py loaddata <fixturename>, where <fixturename> is the name of the fixture file you’ve created. Each

Upvotes: 2

Related Questions