Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django数据库查询给出意外的';非法双';比较字符串时_Python_Mysql_Django_Django Models - Fatal编程技术网

Python Django数据库查询给出意外的';非法双';比较字符串时

Python Django数据库查询给出意外的';非法双';比较字符串时,python,mysql,django,django-models,Python,Mysql,Django,Django Models,我正在努力理解Django数据库查询失败的原因 我的Django查询如下所示: firebaseUID=self.request.query\u params.get('firebaseUID',None) 这个\u user\u profile=UserProfile.objects.filter(firebaseUID=the\u firebaseUID)我想说您的firebaseUID变量保存为double。您应该确保它是一个字符串。这可能会起作用: this_user_profile

我正在努力理解Django数据库查询失败的原因

我的Django查询如下所示:

firebaseUID=self.request.query\u params.get('firebaseUID',None)

这个\u user\u profile=UserProfile.objects.filter(firebaseUID=the\u firebaseUID)
我想说您的
firebaseUID变量保存为double。您应该确保它是一个字符串。这可能会起作用:

this_user_profile = UserProfile.objects.filter(firebaseUID=str(the_firebaseUID))
查询应转换为:

SELECT `userprofile_userprofile`.`id`, `userprofile_userprofile`.`user_id`, `userprofile_userprofile`.`firebaseUID` FROM `userprofile_userprofile` WHERE `userprofile_userprofile`.`firebaseUID` = `4929e406-9d75-43e2-afa4-fe641f3e85f5`

python调试器将_firebaseUID报告为str,但我已经按照您的建议完成了,并将变量包装在str()中,但这没有什么区别。Django仍在创建SELECT查询,而没有将\u firebaseUID的值括在引号中。如果我手动编辑并提交查询,在\u firebaseUID的值周围插入引号,MySQL将返回错误:Unknown列(对于\u firebaseUID的值)。但我认为您没有拼写它。您应该在原始SQL查询中编写
firebaseUID
而不是
firebaseUID
。我只是在上面的注释中拼写错误。我认为代码中拼写正确。不知道第一个错误发生了什么,为什么不使用引号对其进行解析。但是第二个,没有意义。它表示您的
userprofile
表没有
firebaseUID
属性。如果这是真的,那么当你尝试不加引号的时候,它也应该触发。所以,是的,我一直认为你拼写错了;是的,我是这么想的,但我已经检查了三次了!