【问题标题】:Custom MySQL bigint(11) comparisons are failing自定义 MySQL bigint(11) 比较失败
【发布时间】:2012-10-03 08:37:57
【问题描述】:

我的程序中似乎有一个错误,这很奇怪。为了测试,我在 manage.py shell 上运行了一些非常简单的命令。

models = Model.objects.all()

for model in models :
   print model.field

output: 
0
0
0
0
100004398604871
576962717
576962717
576962717

现在是奇怪的部分:

Model.objects.extra(where = ["field= 576962717"])
output:
[]

Model.objects.extra(where = ["field= 100004398604871"])
output:
[]

# But!!

Model.objects.extra(where = ["field= 0"])
output:
[a bunch of models, aka this one worked]

所以很明显,大 int 比较有问题。我检查了我的 mysql 数据库结构和我的模型以确保它们对齐,并且它们做到了:

我的 mysql cols 被标记为 bigint(11)

而我的 django 模型是 BigIntegerField(editable=False)

有什么想法吗?谢谢

【问题讨论】:

  • 看到您自己修复了错误,您可能会停止将显示长度添加到整数列,因为它们显然弊大于利:)
  • 据说用整数定义的11或20是无关紧要的。将 11 更改为 20 是否解决了您的问题?另外,不写像 models.filter(field=576962717) 这样的“普通” Django 有什么特别之处吗?
  • 你说得对,问题最终得到了解决,但原因不同,但也没有好转。忘记清除缓存。

标签: python mysql django orm


【解决方案1】:

天哪,我慢了,我忘了它应该是 bigint(20) 而不是 11,抱歉!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-26
    • 1970-01-01
    • 1970-01-01
    • 2017-11-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多