1

So usually in django you have an app let's say common you create and inside it can have a model lets say Site and you can dumpdata from the model like so python manage.py dumpdata common.site > sites.json and it works but this python manage.py loaddata common.site < sites.json doesn't work.

I'm curious if this is possible or not, if you know how to please share an example.

2
  • Yes you can do it, There is an example here. If you got any error, please show it. Commented Mar 2, 2020 at 12:08
  • Or, you can use fixtures, although they load the data every time the project reloads instead of only when you want. Commented Mar 2, 2020 at 12:15

1 Answer 1

1

To load data to the table you just need to use:

python manage.py loaddata <filename>

python manage.py loaddata sites.json

Refer Django docs: https://docs.djangoproject.com/en/3.0/ref/django-admin/#loaddata

If the JSON is created using dumpdata the file already has the table name and app name no need to specify the app/model name along with the loaddata command.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.