django遇到问题
django.core.exceptions.The SECRET_KEY setting must not be empty.
在django项目settings.py 里引入模块引起的,原因是导入包位置不对。
setting中有一行定义了SECRET_KEY,因为启动项目初始化时读取setting是自上而下。
当读取你导入的包时,在SECRET_KEY上面,则会报没有定义SECRET_KEY的错
RuntimeError: Model class user.models.UserAccount doesn’t declare an explicit app_label
方案一、删除关于模型层from xxx import UserAccount的引用(不推荐此方法)
方案二、
检查注册app的settings文件,是否是这样注册的:'apps.user'(apps为装app文件夹)
检查你引用UserAccount的地方,是否这样引用:from apps.user.models import UserAccount
检查urls.py的引用是否是这样引用:apps.user.urls
若还有错误继续检查有引用模型文件夹下.py文件的地方,
把 user 的引用改为 apps.user 的引用
将
from xxx.apps.users.models import User
改为
from users.models import User
ValueError: The field admin.LogEntry.user was declared with a lazy reference to ‘system.users’, but app ‘system’ isn’t installed.
数据库迁移报错
处理:
进入python3.7/site-packages/django/contrib/admin/migrations目录,把除了__init__.py的文件都删除
> ls
0001_initial.py 0003_logentry_add_action_flag_choices.py __init__.py
0002_logentry_remove_auto_add.py 0004_auto_20200916_1353.py
> rm -rf 000*
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency contenttypes.0002_remove_content_type_name on database ‘default’.
数据库迁移报错
处理:
1.上述方法删除000开头的文件
2.删除代码migrations目录下000开头的文件
3.重新执行 python manage.py makemigrations
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency users.0001_initial on database ‘default’.
AbstractUser 替换user Model,在migrate时报错
处理:
1.注释admin
INSTALLED_APPS = [
# 'django.contrib.admin',
...
]
不要忘记注释urls.py --> path('admin/', admin.site.urls)
2.migrate
python manage.py migrate
3.取消注释
INSTALLED_APPS = [
'django.contrib.admin',
...
]
ValueError: Dependency on app with no migrations: account
原因没有迁移表造成的:
python manage.py makemigrations
python manage.py migrate