I have been working on a project for a while, and I have been having no trouble with migrations. I decided reset the database and migrations, which I do from time to time. I went to delete all migrations, make them again, and after recreating the database, apply the migrations, at which point, I get the error "Migration users.0001_initial is applied before its dependency auth.0012_alter_user_first_name_max_length on database 'default'.
"
Now, auth.0012_alter_user_first_name_max_length
is apparently coming from django.contrib.auth
, which is part of core django, so I don't see why I need any dependency on its migrations for a new project, yet whenever I make migrations on this project from the beginning, it adds a dependency to my user model of auth.0012_alter_user_first_name_max_length
. I don't know why it does that, when it apparently wasn't doing that yesterday, but I am now having to remove that dependency from the user migration manually before it will migrate.
What might cause this.
Here is my users.models.py file. Maybe someone can figure out what would be so odd about it that it would do this.
from django.contrib.auth.models import AbstractUser from django.db.models import CharField, EmailField from django.urls import reverse from django.utils.translation import gettext_lazy as _ from phonenumber_field.modelfields import PhoneNumberField from django.contrib.auth.models import UserManager from django.db.models import Q # Override UserManager and allow login with both username and email address class CustomUserManager(UserManager): def get_by_natural_key(self, username): return self.get( Q(**{self.model.USERNAME_FIELD: username}) | Q(**{self.model.EMAIL_FIELD: username}) ) class User(AbstractUser): class Meta(object): unique_together = ('email',) email = EmailField(_('email address'), unique=True, blank=True, max_length=255) phone_number = PhoneNumberField(_('Phone number'), blank=True) address = CharField(_("Street address"), blank=True, max_length=255) city = CharField(_("City"), blank=True, max_length=255) state = CharField(_("State"), blank=True, max_length=255) zip = CharField(_("ZIP"), blank=True, max_length=255) USERNAME_FIELD = 'username' REQUIRED_FIELDS = ['first_name', 'last_name', 'email'] # for allowing both username and email login objects = CustomUserManager() def get_absolute_url(self): """Get url for user's detail view. Returns: str: URL for user detail. """ return reverse("users:detail", kwargs={"username": self.username})
https://stackoverflow.com/questions/65540414/django-claiming-inconsistent-migration-history-on-first-migration January 02, 2021 at 10:51PM
没有评论:
发表评论