Reputation: 13
Django==4.2.4 In production, postgresql. In local, sqlite(django's default)
INSTALLED_APPS = [
'snsapp.apps.SnsappConfig',My app
'allauth',
'allauth.account',
'allauth.socialaccount',
'bleach',
'widget_tweaks',
'django_ckeditor_5',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites', Added
'django.contrib.sitemaps',Added
]
I added site and sitemap to create a sitemap.
Then, executed this command in local
python3 manage.py migrate
raise InconsistentMigrationHistory(
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration socialaccount.0001_initial is applied before its dependency sites.0001_initial on database 'default'.
How can I resolve this? I want to avoid deleting data and experiencing downtime because I've already released this product.
PS. Since allauth.socialaccount was not used by me, I solved the problem by deleting it from installed_apps and migrate. If there is data in socialaccount, I think makemigrations, then migrate, then delete the data, then add sites and migrate.
The cause is that I didn't write 'django.contrib.sites' together. During the learning process, I didn't write it because I didn't think it had anything to do with allauth at a glance. Also, I think if you use them together, you need to put them above socialaccount or you will get an error (because the social account migration is applied before sites).
I'm sure there are others who have similar questions, so I'll leave the question as is.
Sites that might be helpful
Now it looks like you have to be a paying member to see it. I was able to see it before. It is the exact same error and the same cause. I think the content was something about making a backup and deleting the file. In that case, wouldn't it be unusable during that time? I think so, but depending on the situation, this may solve the problem.
I didn't write how to reproduce it.
'allauth',
'allauth.account',.
'allauth.socialaccount',
and migrate, then add 'django.contrib.sites' and migrate, you will get the same error.
Upvotes: 0
Views: 147
Reputation: 1329
If your production database does not already have data in the allauth.socialaccount
tables, then you can run a migration to undo the allauth socialaccount migrations and then install it into the database again:
python3 manage.py migrate socialaccount zero
django.contrib.sites
app in INSTALLED_APPS
python3 manage.py migrate sites
python3 manage.py migrate socialaccount
The re-migration is required because allauth.socialaccount
migrations are dynamic and change based on whether django.contrib.sites
is in INSTALLED_APPS
, even if you have already run the socialaccount migrations.
Upvotes: 0