标签:models red required details sub database 错误 data foreign
与mysql不兼容
ImproperlyConfigured: mysqlclient 1.3.13 or newer is required
添加新版组件:
pip install mysqlclient
移除旧版组件:
pip uninstall pymysql
删除app目录下pymysql调用
import pymysql
pymysql.install_as_MySQLdb()
FoginKey报错:
TypeError: CASCADE() missing 4 required positional arguments: ‘collector‘, ‘field‘, ‘sub_objs‘
author_detail = models.OneToOneField("AuthorDetails", on_delete=models.CASCADE())
models.CASCADE不能加()
author_detail = models.OneToOneField("AuthorDetails", on_delete=models.CASCADE)
ORM报错:
解决ORM错误:django.db.utils.IntegrityError: (1452, ‘Cannot add or update a child row: a foreign key constraint fails
settings.py:取消外键检查
# settings.py
# 取消外键检查
‘OPTIONS‘:{
"init_command":"SET foreign_key_checks = 0;",
# 完整:
DATABASES = {
‘default‘: {
‘ENGINE‘: ‘django.db.backends.mysql‘,
‘NAME‘: ‘test‘,
‘HOST‘:‘127.0.0.1‘,
‘PORT‘:3306,
‘USER‘:‘root‘,
‘PASSWORD‘:‘123‘,
‘OPTIONS‘: {
"init_command": "SET foreign_key_checks = 0;",
}
}
}
标签:models red required details sub database 错误 data foreign
原文地址:https://www.cnblogs.com/relaxlee/p/12842917.html