[PYTHON] django data input dumpdata loaddata

reference https://docs.djangoproject.com/ja/3.0/ref/django-admin/

Create a fixtures directory directly under the application

mysite
  ├ mysite
  │   ├ settings.py
  └ polls
      ├ admin.py
└ fixtures ← Make here

The default is json format

Database → File

python manage.py dumpdata polls > polls/fixtures/data.json

For a specific model only

python manage.py dumpdata polls.Question > polls/fixtures/Question.json

File → Database

python manage.py loaddata polls/fixtures/data.json

I am easy to see yaml

If you use yaml format, you need PyYAML, so enter it.

pip install PyYAML

Database → File

python manage.py dumpdata --format=yaml polls > polls/fixtures/data.yaml

File → Database

python manage.py loaddata --format=yaml polls/fixtures/data.yaml

Recommended Posts

django data input dumpdata loaddata
Save tweet data with Django
Data acquired by Django releted
Django input check and calendar input
Set placeholders in input fields in Django