0

I have implemented a CustomUser model on users app in django.

class CustomUser(AbstractUser):
username = None
email = models.EmailField('email address', unique=True)
first_name = models.CharField('First Name', max_length=255, blank=True,
                              null=False)
last_name = models.CharField('Last Name', max_length=255, blank=True,
                             null=False)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username']

def __str__(self):
    return f"{self.first_name} {self.last_name}"

And then when running "python manage.py migrate", I got this error "django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency users.0001_initial on database 'default'."

  • Have you deleted any `migrations` files? This same question can help you https://stackoverflow.com/q/44651760/17562044 – Sunderam Dubey Apr 21 '22 at 15:14
  • https://docs.djangoproject.com/en/4.0/topics/auth/customizing/#changing-to-a-custom-user-model-mid-project: `Changing AUTH_USER_MODEL after you’ve created database tables is significantly more difficult since it affects foreign keys and many-to-many relationships, for example. This change can’t be done automatically and requires manually fixing your schema, moving your data from the old user table, and possibly manually reapplying some migrations. See #25313 for an outline of the steps.` - https://code.djangoproject.com/ticket/25313 – Iain Shelvington Apr 21 '22 at 15:16
  • On https://code.djangoproject.com/ticket/25313 I checked the issues and solved it, Thanks for your kind reply. – ziqiang jin Apr 21 '22 at 23:29

0 Answers0