简体   繁体   English

Django - makemigrations 后无法迁移

[英]Django - cannot migrate after makemigrations

I am not able to migrate this code after makemigrations.在 makemigrations 之后我无法迁移此代码。

When I type python manage.py migrate , it is showing me no migration to apply.当我输入python manage.py migrate时,它显示我没有要应用的迁移。

class MyUserManager(BaseUserManager):
    def create_user(self,email,firstname,lastname,password=None):
        if not password:
            raise ValueError("user must have password")
        if not email:
            raise ValueError("User must have an email address")
        user = self.model(
            email=self.normalize_email(email)
            )

        user.set_password(password)
        user.save(using=self._db)
        return user

    def create_superuser(self, email, date_of_birth, password=None):
        
        user = self.create_user(
            email,
            password=password,
            
        )
        user.is_admin = True
        user.save(using=self._db)
        return user


class MyUser(AbstractBaseUser):
    email = models.EmailField(max_length=100,default="emaple@exampll.com",unique=True)
    firstname = models.CharField(max_length=100,default="FirstName")
    lastname = models.CharField(max_length=100,default="LastName")
    date_of_birth = models.DateField(default=timezone.now)
    active = models.BooleanField(default=True)
    admin = models.BooleanField(default=False)
    staff = models.BooleanField(default=False)

    USERNAME_FIELD = 'email'
    REQUIERD_FIELDS = []

    objects = MyUserManager()

    def __str__(self):
        return self.firstname + self.lastname
    
    @property
    def is_staff(self):
        return self.staff
    
    @property
    def is_admin(self):
        return self.admin

    @property
    def is_active(self):
        return self.active

If it says "no migrations to apply", it means that you don't need to migrate anything and the server is ready to run.如果它说“没有要应用的迁移”,则意味着您不需要迁移任何东西并且服务器已准备好运行。 You only need to migrate after you committed changes to your database, and if you didn't, you can safely continue to run your server without migrating anything您只需要在对数据库提交更改后进行迁移,如果您不这样做,您可以安全地继续运行您的服务器而无需迁移任何内容

i found the problem in my code that I was getting,actually I was using builit user model first and then I decided to code for custom user model, in database the builtin usermodel was working fine and custom usermodel was not migrating.我在我的代码中发现了问题,实际上我首先使用的是内置用户 model,然后我决定为自定义用户 model 编写代码,在数据库中,内置用户模型工作正常,自定义用户模型没有迁移。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM