user3541631
user3541631

Reputation: 4008

InconsistentMigrationHistory - Migration .. is applied before its dependency

I have 2 models which are interdependent one of another:

class Account(models.Model):
    created_by = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True,related_name='%(app_label)s_%  (class)s_created_by', on_delete=models.CASCADE)
    updated_by = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, related_name='%(app_label)s_%(class)s_updated_by', on_delete=models.CASCADE)


class User(AbstractBaseUser, MetaData, PermissionsMixin):
    account = models.ForeignKey(Account, blank=True, null=True, related_name='owner', on_delete=models.CASCADE)

I have issues:

InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency users.0001_initial on database 'default'.

I tried to remove from the User the account foreign key, migrate User, then migrate accounts, account FK fails, same error.

I tried to do it starting from the Account it fails, removing FK to users.

I'm interested in doing it on a new database(server) and reset on an old database local.

On the old database, I removed my models from django_migrations, and commented the dependencies between Models and associated foreign key. Tried a fake migration, still sees a dependency and I don't understand from where.

Upvotes: 2

Views: 5212

Answers (1)

user3541631
user3541631

Reputation: 4008

I solved the issue, it was not directly related to Account, but Django Admin migrations, because I used a custom user, in django_migrations, the user migrated after admin, and I had to switch the lines.

Upvotes: 1

Related Questions