# raise InconsistentMigrationHistory

**URL:** <https://forum.djangoproject.com/t/raise-inconsistentmigrationhistory/16660>\
**Category:** Mystery Errors\
**Created:** [October 26, 2022, 6:14am UTC](https://forum.djangoproject.com/t/raise-inconsistentmigrationhistory/16660 "2022-10-26T06:14:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kmantilla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kmantilla/32/10562_2.png) [@kmantilla](https://forum.djangoproject.com/u/kmantilla)\
**Post date:** [October 26, 2022, 6:14am UTC](https://forum.djangoproject.com/t/raise-inconsistentmigrationhistory/16660/1 "2022-10-26T06:14:54Z")

</div>

Sometimes, when I mess around, I get this error when I try to migrate:

```auto
    raise InconsistentMigrationHistory(
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration socialaccount.0001_initial is applied before its dependency sites.0001_initial on database 'default'.

```

What does this mean?

And how should I go about fixing it without wholly dropping my database?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [October 26, 2022, 12:49pm UTC](https://forum.djangoproject.com/t/raise-inconsistentmigrationhistory/16660/2 "2022-10-26T12:49:58Z")

</div>

What exactly do you mean by

> [@kmantilla](#):
>
> when I mess around

?

If at any time you are deleting migration files, don’t do that unless you become really familiar with how migrations work.

See:

- [Migrations | Django documentation | Django](https://docs.djangoproject.com/en/4.1/topics/migrations/)
- [Migration Operations | Django documentation | Django](https://docs.djangoproject.com/en/4.1/ref/migration-operations/)
- [How to create database migrations | Django documentation | Django](https://docs.djangoproject.com/en/4.1/howto/writing-migrations/)

and get familiar with the migrations table that Django creates in your database.

You generally can resolve problems like this, but fixing it is going to (possibly) involve editing some number of migration files and manually editing the migrations table.

---

<div class="post-metadata">

**Author:** ![kmantilla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kmantilla/32/10562_2.png) [@kmantilla](https://forum.djangoproject.com/u/kmantilla)\
**Post date:** [October 26, 2022, 1:05pm UTC](https://forum.djangoproject.com/t/raise-inconsistentmigrationhistory/16660/3 "2022-10-26T13:05:45Z")

</div>

for example, adding `'django.contrib.sites',` to `INSTALLED_APPS` creates this error for me.

---

<div class="post-metadata">

**Author:** ![kmantilla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kmantilla/32/10562_2.png) [@kmantilla](https://forum.djangoproject.com/u/kmantilla)\
**Post date:** [October 26, 2022, 1:13pm UTC](https://forum.djangoproject.com/t/raise-inconsistentmigrationhistory/16660/4 "2022-10-26T13:13:03Z")

</div>

I fixed the problem by dropping a few rows in the django\_migration table and dropping any socialaccount table related to allauth.
