Search code examples
pythondjangodjango-modelsdjango-rest-frameworkdeployment

Migration error(Migration is applied before its dependency accounts.0001_initial on database 'default')


I'm trying to migrate my custom user model and I run makemigrations command to make migrations for new models. But when I run migrate command it throws this error :

raise InconsistentMigrationHistory( django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency accounts.0001_initial on database 'default'.

Trace back:

Traceback (most recent call last):
  File "C:\Users\enosh\venv_ruling\ruling\manage.py", line 22, in <module>
    main()
  File "C:\Users\enosh\venv_ruling\ruling\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\enosh\venv_ruling\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "C:\Users\enosh\venv_ruling\lib\site-packages\django\core\management\__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\enosh\venv_ruling\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\enosh\venv_ruling\lib\site-packages\django\core\management\base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "C:\Users\enosh\venv_ruling\lib\site-packages\django\core\management\base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "C:\Users\enosh\venv_ruling\lib\site-packages\django\core\management\commands\migrate.py", line 95, in handle
    executor.loader.check_consistent_history(connection)
  File "C:\Users\enosh\venv_ruling\lib\site-packages\django\db\migrations\loader.py", line 306, in check_consistent_history

models.py

from django.contrib.auth.models import AbstractUser


class CustomUser(AbstractUser):
    """extend usermodel"""

    class Meta:
        verbose_name_plural = 'CustomUser'

I just mentioned user model in this question but still if more code is required then tell me I'll update my question with that information. Thank you


Solution

    1. Delete the DB
    2. Delete pycache and migrations from all the apps
    3. Make sure you have set AUTH_USER_MODEL
    4. Make migrations