当前位置:  开发笔记 > 编程语言 > 正文

迁移时Django FieldDoesNotExist异常

如何解决《迁移时DjangoFieldDoesNotExist异常》经验,为你挑选了0个好方法。

使用django 1.9.所以我试图迁移我的数据库但是我遇到了这个错误.我花了很多时间来解决这个问题并且没有成功.如果有必要,我可以上传更多代码.这是错误:

C:\Users\James\Desktop\James\Work\django\homepgcom>python manage.py migrate
Operations to perform:
  Apply all migrations: auth, interface, sessions, admin, contenttypes, userprofile
Running migrations:
  Rendering model states... DONE
  Applying interface.0002_auto_20160107_1635...Traceback (most recent call last):  
File "C:\Users\James\AppData\Local\Programs\Python\Python35\lib\site-packages\django\db\models\options.py", line 580, in get_field
return self.fields_map[field_name]
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in 
execute_from_command_line(sys.argv)
File "C:\Users\James\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\management\__init__.py", line 350, in execute_from_command_line
utility.execute()
File "C:\Users\James\AppData\Local\Programs\Python\Python35\lib\site-packages\
django\core\management\__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\James\AppData\Local\Programs\Python\Python35\lib\site-packages\
django\core\management\base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\James\AppData\Local\Programs\Python\Python35\lib\site-packages\
django\core\management\base.py", line 399, in execute
output = self.handle(*args, **options)
File "C:\Users\James\AppData\Local\Programs\Python\Python35\lib\site-packages\
django\core\management\commands\migrate.py", line 200, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\James\AppData\Local\Programs\Python\Python35\lib\site-packages\
django\db\migrations\executor.py", line 92, in migrate
self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\James\AppData\Local\Programs\Python\Python35\lib\site-packages\
django\db\migrations\executor.py", line 121, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\James\AppData\Local\Programs\Python\Python35\lib\site-packages\
django\db\migrations\executor.py", line 198, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\James\AppData\Local\Programs\Python\Python35\lib\site-packages\
django\db\migrations\migration.py", line 123, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\James\AppData\Local\Programs\Python\Python35\lib\site-packages\
django\db\migrations\operations\fields.py", line 201, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "C:\Users\James\AppData\Local\Programs\Python\Python35\lib\site-packages\
django\db\backends\base\schema.py", line 482, in alter_field
old_db_params, new_db_params, strict)
File "C:\Users\James\AppData\Local\Programs\Python\Python35\lib\site-packages\
django\db\backends\sqlite3\schema.py", line 245, in _alter_field
self._remake_table(model, alter_fields=[(old_field, new_field)])
File "C:\Users\James\AppData\Local\Programs\Python\Python35\lib\site-packages\
django\db\backends\sqlite3\schema.py", line 181, in _remake_table
self.create_model(temp_model)
File "C:\Users\James\AppData\Local\Programs\Python\Python35\lib\site-packages\
django\db\backends\base\schema.py", line 250, in create_model
to_column = field.remote_field.model._meta.get_field(field.remote_field.field_name).column
File "C:\Users\James\AppData\Local\Programs\Python\Python35\lib\site-packages\
django\db\models\options.py", line 582, in get_field
raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, field_name))
django.core.exceptions.FieldDoesNotExist: User has no field named None

提前谢谢了!

推荐阅读
jerry613
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有