Django dumpdata (with no app specified) dumps all the tables of all the installed apps to an output file. I just realized this did not include the django_migrations table. I checked the other django tables, they were included as they were specified in the INSTALLED_APPS setting as follows:
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
Now, I am curious, why wasn't the django_migrations table not dumped. The rationale seems to be when you create a new database and migrate, it will be generated and populated with data automatically. Is this correct? If so, my second question would be is there a way to dump it as well (as a back up)? I am new to django and trying new things I might break that table. It would be handy to have a back up.
A note to others, django_migrations
is not the only table excluded, django_site
is also excluded (only applicable if you are using Django's site feature).
The implications is that when you restore your database, after you migrate, do NOT delete the data created by your migrations for those two tables. You may have to create a manual entry for django_site if applicable.
Its weird that these tables:
'auth_group_permissions',
'auth_permission',
'auth_user',
'django_content_type',
Are created by dump data, and by migrate
. That means if you dump data, be prepared to truncate the above tables first before you can succesfully load data (or exclude them from your dump data command).
The django_migrations table lives outside the conventional Django machinery, that's probably why it wasn't included (per @knbk).
As long as you backup your apps, there is no need to backup the migrations table. You can delete all app tables and re-migrate everything. While you are at it, you may also want to squash your migrations at this point by either using the squash command or by deleting all migrations and creating from scratch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With