django fixtures. To dump data
Step 1: Open a terminal window.
Step 2: Navigate to your Django project directory using the cd
command.
Step 3: Run the following command to create a JSON or XML fixture file for one or more Django apps:
python manage.py dumpdata app_name > app_name_fixture.json
Replace "app_name" with the actual name of the app for which you want to create the fixture file.
Step 4: Optionally, you can include the --indent
option to format the output with indentation for better readability:
python manage.py dumpdata app_name --indent 2 > app_name_fixture.json
Step 5: To create a fixture file for all apps in your project, use the following command:
python manage.py dumpdata > all_apps_fixture.json
Step 6: Verify the created fixture file to ensure it contains the desired data.
Step 7: To load the data from the fixture file into the database, use the following command:
python manage.py loaddata app_name_fixture.json
Replace "app_name_fixture.json" with the actual fixture file name.
Step 8: Verify that the data has been successfully loaded into the database.
Note: Ensure that the database schema is consistent with the data in the fixture file before loading the data. If needed, you can use migrations to synchronize the schema.