我正在尝试为我的项目制作定制的用户模型Django
.
My 模型.py:
class myCustomeUser(AbstractUser):
id = models.AutoField(primary_key=True)
username = models.CharField(max_length=20, unique="True", blank=False)
password = models.CharField(max_length=20, blank=False)
is_Employee = models.BooleanField(default=False)
is_Inspector = models.BooleanField(default=False)
is_Industry = models.BooleanField(default=False)
is_Admin = models.BooleanField(default=False)
class Industry(models.Model):
user = models.OneToOneField(myCustomeUser, on_delete=models.CASCADE, primary_key=True, related_name='industry_releted_user')
name = models.CharField(max_length=200, blank=True)
owner = models.CharField(max_length=200, blank=True)
license = models.IntegerField(null=True, unique=True)
industry_extrafield = models.TextField(blank=True)
class Employee(models.Model):
user = models.OneToOneField(myCustomeUser, on_delete=models.CASCADE, primary_key=True, related_name='employee_releted_user')
industry = models.OneToOneField(Industry, on_delete=models.CASCADE, related_name='employee_releted_industry')
i_id = models.IntegerField(null=True, blank=False, unique=True)
name = models.CharField(max_length=200, blank=False, null=True)
gmail = models.EmailField(null=True, blank=False, unique=True)
rank = models.CharField(max_length=20, blank=False, null=True)
employee_varified = models.BooleanField(default=False)
class Inspector(models.Model):
user = models.OneToOneField(myCustomeUser, on_delete=models.CASCADE, primary_key=True, related_name='inspector_releted_user')
inspector_extrafield = models.TextField(blank=True)
class Admin(models.Model):
user = models.OneToOneField(myCustomeUser, on_delete=models.CASCADE, primary_key=True, related_name='admin_releted_user')
admin_extrafield = models.TextField(blank=True)
in 设置.py:
AUTH_USER_MODEL = 'app.myCustomeUser'
Here admin.site.register
也完成在admin.py
。现在,当我尝试时,它在终端中显示以下消息migrate
or makemigrations
:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "G:\Python\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "G:\Python\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "G:\Python\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "G:\Python\lib\site-packages\django\core\management\base.py", line 369, in execute
output = self.handle(*args, **options)
File "G:\Python\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "G:\Python\lib\site-packages\django\core\management\commands\makemigrations.py", line 101, in handle
loader.check_consistent_history(connection)
File "G:\Python\lib\site-packages\django\db\migrations\loader.py", line 295, in check_consistent_history
raise InconsistentMigrationHistory(
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency app.0001_initial on database 'default'.
这是什么意思?而且我也不想设置默认值username
& password
在这个myCustomeUser
模型。还请建议我,这是正确的方法吗usermodel
?