'NoneType' object has no attribute 'is_relation',报错原因定位

简介:

问题

  • 平时在生成migrate文件时,如果出现问题,一般都会显示失败的原因,造成失败的是哪个字段,但是也有可能会出现这种情况:

      File "/venv/lib/python3.5/site-packages/django/db/migrations/operations/fields.py", line 148, in state_forwards
    delay = not old_field.is_relation
    AttributeError: 'NoneType' object has no attribute 'is_relation'
  • 这样仅仅看报错的信息就没办法准确的定位自己失败的原因了。

解决方法

  • 修改文件环境路径 + /lib/python3.5/site-packages/django/db/migrations/operations/fields.py
    20200119194240261
  • 打开文件,根据报错提示,找到第148行,在state_forwards方法中加入以下代码:

    print(app_label + " " + self.model_name_lower + " " + self.name)
  • 再次执行makemigrations。就会打印出执行时makemigrations走到了哪一个字段。
  • 然后就可以根据报错前打印的字段名,定位到问题字段,这样就可以更快的查到错误原因了。

参考链接:Django makemigrations 报错原因定位

相关文章
|
30天前
|
计算机视觉 Python
解决 NoneType‘ object has no attribute ‘astype’ 问题
解决 NoneType‘ object has no attribute ‘astype’ 问题
26 0
|
5月前
|
存储 JSON 数据格式
数据集加载时报错'dict' object has no attribute 'requests‘
数据集加载时报错'dict' object has no attribute 'requests‘
107 5
|
3月前
AttributeError: 'NoneType' object has no attribute 'to_capabilities'
AttributeError: 'NoneType' object has no attribute 'to_capabilities'
361 0
|
6月前
|
Python Windows
xlrd库报错【AttributeError: ‘ElementTree‘ object has no attribute ‘getiterator‘】
xlrd库报错【AttributeError: ‘ElementTree‘ object has no attribute ‘getiterator‘】
116 0
|
3月前
AttributeError ‘NoneType‘ object has no attribute ‘to_capabilities‘
AttributeError ‘NoneType‘ object has no attribute ‘to_capabilities‘
90 0
|
4月前
|
数据采集
运行爬虫时报错AttributeError—— 'str' object has no attribute 'capabilities'
运行爬虫时报错AttributeError—— 'str' object has no attribute 'capabilities'
221 0
|
4月前
'WebDriver' object has no attribute 'find_element_by_tag_name'
'WebDriver' object has no attribute 'find_element_by_tag_name'
112 0
|
8月前
yolov7—tensorrt报错AttributeError: ‘NoneType‘ object has no attribute ‘execute_v2‘已解决。
yolov7—tensorrt报错AttributeError: ‘NoneType‘ object has no attribute ‘execute_v2‘已解决。
83 0
yolov7—tensorrt报错AttributeError: ‘NoneType‘ object has no attribute ‘execute_v2‘已解决。
|
5月前
|
Java
java判断Object对象是否为空demo
java判断Object对象是否为空demo
|
6天前
|
JavaScript
js 字符串String转对象Object
该代码示例展示了如何将一个以逗号分隔的字符串(`'1.2,2,3,4,5'`)转换为对象数组。通过使用`split(',')`分割字符串并`map(parseFloat)`处理每个元素,将字符串转换成浮点数数组,最终得到一个对象数组,其类型为`object`。