赞
踩
错误一:ValueError: Cannot assign "<QuerySet [<User: user>]>": "SwitchRecord.user_id" must be a "User" instance.
原因: # 外键django用户id class SwitchRecord(models.Model): user_id = models.ForeignKey('User', on_delete=models.SET(0))
解决方法:传入User实例test_user[0] test_user = User.objects.filter(id=8) print(type(test_user[0]))
错误二:AttributeError: 'QuerySet' object has no attribute 'id'
原因: User.objects.filter(id=8)返回的是QuerySet类
错误三:raise AppRegistryNotReady("Apps aren't loaded yet.")
错误原因:xxx.settings INSTALLED_APPS配置有误,错误如下图
去除xxx.models,django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.报错解决
错误四
解决错误三后又报错:RuntimeError: Model class models.User doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
原因:使用相对路径导包 from models import User 解决方法:使用绝对路径导包 from xxx.models import User
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。