4👍
You can change this part models.MyModel.objects.all()
to get selective data in fixtures.
from django.core import serializers
from myproject.myapp import models
data = serializers.serialize("json", models.MyModel.objects.all())
out = open("mymodel.json", "w")
out.write(data)
out.close()
1👍
Need to use dumpdata e.g.
python manage.py dumpdata --format=json --indent=2 --exclude=admin --exclude=sessions > test_db.json
Here I am dumping everything in the database excluding the admin and sessions tables (my guess is you might not need those), into a json file named test_db.json
. I’m also using an indent of 2 spaces to make the file more easy to inspect by eye.
- [Django]-Django FilteredSelectMultiple not rendering on page
- [Django]-Location of static files when creating a Django exe using pyinstaller
- [Django]-Django groups, roles and permissions
- [Django]-Django Framework: Object does not display on web page for specific pk
- [Django]-Pip install requirements.txt issue when deploying Django app on Heroku
0👍
You can try to use mysqldump :
You will need to lookup all the names of the tables you want to dump. To get the full list you can use :
mysqlshow db_name
Then run :
mysqldump db_name table_1 table_2 table_3 table_4
This command will output the result to the standard output, if you want it to write to a file, use --result-file=/path/to/file
See also the full documentation for mysqldump : http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html
- [Django]-Best JSON library to get JSON data for Django?
- [Django]-How to install python3 and Django using userdata in AWS EC2 with aws cli boto3