- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正尝试在 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
中完成的。现在,当我尝试 migrate
或 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'.
这是什么意思?而且我也不想在此 myCustomeUser
模型中设置 username
& password
的默认值。也请建议我,这是制作 usermodel
的正确方法吗?
最佳答案
我也有同样的问题,但我只是从每个应用程序中删除了我的迁移,并删除了数据库,然后创建了一个新的。并使用`
python manage.py makemigrations
python manage.py migrate
进行新的迁移,一切正常。
关于python - 迁移 admin.0001_initial 在其对数据库 'default' 的依赖 app.0001_initial 之前应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65562875/
这是我的代码。 var express = require("express"); var router = express.Router(); var mangojs = require("mang
知道为什么我在运行下面的代码时会收到以下错误: Traceback (most recent call last): File "C:\pytests\mthread1.py", line 25,
我正在尝试学习 Python 3 上的线程。我做了一个示例代码: import time import threading def myfunction(string,sleeptime,lock,*
下面的代码不会在我的 ASP.NET 页面中呈现,并且单击按钮后我的页面会发回。 Sys dot WebForms dot PageRequestManager dot _initialize('Sc
我在网站上使用 ASP.NET 2.0 Ajax 扩展。与往常一样,本地一切正常,但远程网站不使用 ajax 调用。我的本地服务器安装了 ASP.NET Ajax 扩展,但远程服务器没有。我知道我应该
我是一名优秀的程序员,十分优秀!