-
Notifications
You must be signed in to change notification settings - Fork 3
Changing the database model
Caroline Fischer edited this page Dec 10, 2023
·
6 revisions
When the database model in models.py is changed a new migration has to be created specifying how to change to the new database format. This can be done by
python manage.py makemigrations --settings=config.settings.local
The migration might have to be improved, e.g. by using migrations.RunPython
.
Afterwards the test database has to be updated as well. Use the dumpdata command to generate a test database from the currently running database:
python -Xutf8 manage.py dumpdata -e contenttypes -e auth.Permission -e admin.LogEntry -e sessions --indent 2 --settings=config.settings.local > e2e_tests/database/test_database.json
Check the diff of e2e_tests/database/test_database.json
for any unexpected parts and adjust as necessary.
git checkout right-before-model-change
rm db/db.sqlite3
python manage.py migrate --settings=config.settings.local
python manage.py loaddata --settings=config.settings.local e2e_tests/database/test_database.json
cp -r e2e_tests/database/test_database_uploads/. cpmonitor/images/uploads
git checkout after-model-change-including-migration
python manage.py migrate --settings=config.settings.local
python -Xutf8 manage.py dumpdata -e contenttypes -e auth.Permission -e admin.LogEntry -e sessions --indent 2 --settings=config.settings.local > e2e_tests/database/test_database.json
# if additional images were uploaded:
cp -r cpmonitor/images/uploads e2e_tests/database/test_database_uploads