![](/img/trans.png)
[英]AttributeError: 'NoneType' object has no attribute 'is_relation'
[英]'NoneType' object has no attribute 'is_relation' error on Django Migrations
我試圖從Heroku上的Django現有模型中刪除一些字段,因此我運行了make遷移,然后遷移了命令,好像遷移成功了。
之后,我發現缺少一個字段,因此我自己創建了下一個遷移文件,並將依賴項放到了先前自動生成的遷移文件中。 當我運行它時,會出現如下錯誤:
~ $ python manage.py migrate
Operations to perform:
Apply all migrations: API, admin, auth, authtoken, contenttypes, sessions
Running migrations:
Applying API.0007_timezoneremoval...Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 115, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/migration.py", line 119, in apply
operation.state_forwards(self.app_label, project_state)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 150, in state_forwards
delay = not old_field.is_relation
AttributeError: 'NoneType' object has no attribute 'is_relation'
該錯誤可能是由何處引起的? 謝謝
你可以去到migrate
文件夾,刪除所有.py
除了文件__init__.py
。
之后,運行:
python manage.py makemigrations
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.