gpt4 book ai didi

python - 迁移 admin.0001_initial 在其对数据库 'default' 的依赖 app.0001_initial 之前应用

转载 作者:行者123 更新时间:2023-12-05 02:02:55 24 4
gpt4 key购买 nike

我正尝试在 Django 中为我的项目制作定制的用户模型。

我的 models.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)

settings.py 中:

AUTH_USER_MODEL = 'app.myCustomeUser'

这里admin.site.register也是在admin.py中完成的。现在,当我尝试 migratemakemigrations 时,它在终端中显示以下消息:

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'.

这是什么意思?而且我也不想在此 myCustomeUser 模型中设置 username & password 的默认值。也请建议我,这是制作 usermodel 的正确方法吗?

最佳答案

我也有同样的问题,但我只是从每个应用程序中删除了我的迁移,并删除了数据库,然后创建了一个新的。并使用`

python manage.py makemigrationspython manage.py migrate

进行新的迁移,一切正常。

关于python - 迁移 admin.0001_initial 在其对数据库 'default' 的依赖 app.0001_initial 之前应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65562875/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com