基数为10的int()的文本无效:“choosen\u room\u 1\u id”

2024-10-01 02:23:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图访问模型自身属性的一部分,但是在迁移之后出现了这个错误。你知道吗

在我运行makemigrationsmigrate之前,这个模型运行得非常好。你知道吗

在阅读了value error页面之后,我注意到value错误是由模型试图在属性函数下访问自己的外键(choosen_room_1)引起的。你知道吗

  Traceback:
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/theblackcat/website/backend/views.py" in dashboard
  54.       return render_to_response('form/dashboard.html', RequestContext(request, locals()))
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/shortcuts.py" in render_to_response
  39.         content = loader.render_to_string(template_name, context, using=using)
  File "/Users/theblackcatwebsite/env/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
  99.         return template.render(context, request)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/backends/django.py" in render
  74.         return self.template.render(context)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/base.py" in render
  210.                     return self._render(context)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/base.py" in _render
  202.         return self.nodelist.render(context)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/base.py" in render
  905.                 bit = self.render_node(node, context)      
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/debug.py" in render_node
  79.             return node.render(context)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  135.         return compiled_parent._render(context)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/base.py" in _render
202.         return self.nodelist.render(context)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/base.py" in render
905.                 bit = self.render_node(node, context)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/debug.py" in render_node
79.             return node.render(context)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/loader_tags.py" in render
65.                 result = block.nodelist.render(context)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/base.py" in render
905.                 bit = self.render_node(node, context)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/debug.py" in render_node
79.             return node.render(context)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/defaulttags.py" in render
329.                 return nodelist.render(context)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/base.py" in render
905.                 bit = self.render_node(node, context)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/debug.py" in render_node
79.             return node.render(context)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/defaulttags.py" in render
217.                             nodelist.append(node.render(context))
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/debug.py" in render
89.             output = self.filter_expression.resolve(context)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/base.py" in resolve
648.                 obj = self.var.resolve(context)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/base.py" in resolve
789.             value = self._resolve_lookup(context)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/template/base.py" in _resolve_lookup
827.                         current = getattr(current, bit)
  File "/Users/theblackcat/website_koref/backend/models.py" in total_price
226.        price,_ = self.getTotalPricing()
  File "/Users/theblackcat/website/backend/models.py" in getTotalPricing
212.        if self.choosen_room_1 is not None:
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/db/models/fields/related.py" in __get__
610.                     qs = qs.filter(**params)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/db/models/query.py" in filter
679.         return self._filter_or_exclude(False, *args, **kwargs)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/db/models/query.py" in _filter_or_exclude
697.             clone.query.add_q(Q(*args, **kwargs))      
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/db/models/sql/query.py" in add_q
1310.         clause, require_inner = self._add_q(where_part, self.used_aliases)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/db/models/sql/query.py" in _add_q
1338.                     allow_joins=allow_joins, split_subq=split_subq,
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/db/models/sql/query.py" in build_filter
1209.             condition = self.build_lookup(lookups, col, value)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/db/models/sql/query.py" in build_lookup
1102.                 return final_lookup(lhs, rhs)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/db/models/lookups.py" in __init__
105.         self.rhs = self.get_prep_lookup()
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/db/models/lookups.py" in get_prep_lookup
143.         return self.lhs.output_field.get_prep_lookup(self.lookup_name, self.rhs)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/db/models/fields/__init__.py" in get_prep_lookup
727.             return self.get_prep_value(value)
  File "/Users/theblackcat/website/env/lib/python2.7/site-packages/django/db/models/fields/__init__.py" in get_prep_value
985.         return int(value)

  Exception Type: ValueError at /en/backend/
  Exception Value: invalid literal for int() with base 10: 'choosen_room_1_id'

型号.py

def getTotalPricing(self):
    total_price = 0
    amount = dict()
    if self.choosen_room_1 is not None:

choosen_room_1属性定义如下:

型号.py

choosen_room_1 = models.ForeignKey(ChoosenRoom, default=None, related_name="room_type_1", null=True)

到目前为止,我试过的一些方法是:

  1. 已删除旧的迁移文件

  2. 检查是否在使用sqlite终端的表中存在id字段,并且它确实存在

  3. 强制选择房间1到字段为idchoosenroom_id,同样的错误仍然存在

  4. 使用Django管理界面,我确信choosenroom不是空的,并且能够用一个新的外键项重新分配它。

  5. 使用访问choosen\u room\u 1管理.pyshell会给我同样的错误。

在阅读了一些stackoverflow问题之后,我猜测foreignkey希望使用integer类型的惟一id键,但是在查询过程中出现了问题?As mention here

顺便说一下,我是在Python2.7和Django1.8.18下运行这个项目的

更新 在刷新了数据库之后,我花了一些时间用类似的数据重新填充数据库,现在它就像一个魔咒。你知道吗


Tags: djangoinpyselfenvlibpackagescontext