'NoneType' object has no attribute 'is_relation'
来源:3-6 migrations原理及表生成
慕数据957128
2019-03-02
最近我自己的DJANGO项目有时在修改model之后,再makemigrations出现下面的错误,好像是数据关联引起的,不管我怎么回退models的代码再migrations,都无法解决,如果我删掉对应APP里的migrations目录,虽然能解决这个报错,但是再make migrations时会报数据表已经存在,会冲突,又不能删掉数据库里的数据,特别是在生产上,数据还有相互关联性,备份、删除、恢复数据是高风险的操作。
我感觉这是DJANGO的一个BUG。
请问bobby老师有没有遇到过这种错误?是如何解决的?百度了很多次,有人遇到过,但是与我的情况又不相同,难以借鉴,谢谢!
Traceback (most recent call last):
File “manage.py”, line 22, in
execute_from_command_line(sys.argv)
File “/home/appman/.virtualenvs/py27/lib/python2.7/site-packages/django/core/management/init.py”, line 364, in execute_from_command_line
utility.execute()
File “/home/appman/.virtualenvs/py27/lib/python2.7/site-packages/django/core/management/init.py”, line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File “/home/appman/.virtualenvs/py27/lib/python2.7/site-packages/django/core/management/base.py”, line 283, in run_from_argv
self.execute(*args, **cmd_options)
File “/home/appman/.virtualenvs/py27/lib/python2.7/site-packages/django/core/management/base.py”, line 330, in execute
output = self.handle(*args, **options)
File “/home/appman/.virtualenvs/py27/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py”, line 150, in handle
loader.project_state(),
File “/home/appman/.virtualenvs/py27/lib/python2.7/site-packages/django/db/migrations/loader.py”, line 323, in project_state
return self.graph.make_state(nodes=nodes, at_end=at_end, real_apps=list(self.unmigrated_apps))
File “/home/appman/.virtualenvs/py27/lib/python2.7/site-packages/django/db/migrations/graph.py”, line 409, in make_state
project_state = self.nodes[node].mutate_state(project_state, preserve=False)
File “/home/appman/.virtualenvs/py27/lib/python2.7/site-packages/django/db/migrations/migration.py”, line 92, in mutate_state
operation.state_forwards(self.app_label, new_state)
File “/home/appman/.virtualenvs/py27/lib/python2.7/site-packages/django/db/migrations/operations/fields.py”, line 149, in state_forwards
delay = not old_field.is_relation
AttributeError: ‘NoneType’ object has no attribute ‘is_relation’
1回答
-
Ethreal
2019-03-03
你业务里面出的问题 难以看出,但是就你提出的这个问题 既然你用django 对数据库的任何修改都要通过数据库迁移命令去操作 重要的话说三遍*3 django在文档中有几种方式 但都不是很方便
062019-03-10
Python前后端分离开发Vue+Django REST framework实战
2873 学习 · 2461 问题
相似问题