2

我正在尝试遵循以下工具包的入门教程django oauth

https://django-oauth-toolkit.readthedocs.io/en/latest/rest-framework/getting_started.html

当我运行时migrate,我收到此错误:

如果 type_ 不是 None 并且 infodict ['type'] != type_: KeyError: 'type'

任何帮助,将不胜感激。

完整的堆栈跟踪

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, oauth2_provider, sessions
Running migrations:
  Applying oauth2_provider.0004_auto_20160525_1623...Traceback (most recent call last):
  File "/Users/lr/lrapp1/manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "/Library/Frameworks/Python.framework/Versions/3.6/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 "/Library/Frameworks/Python.framework/Versions/3.6/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 "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/migration.py", line 129, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 216, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 515, in alter_field
    old_db_params, new_db_params, strict)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 572, in _alter_field
    index_names = self._constraint_names(model, [old_field.column], index=True, type_=Index.suffix)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 1003, in _constraint_names
    if type_ is not None and infodict['type'] != type_:
KeyError: 'type'
4

1 回答 1

4

这个错误似乎是由 oauth2_provider 迁移引起的。您应该可以通过进入 {your venv}/Lib/site-packages/oauth2_provider/migrations 并删除所有迁移文件(init .py 除外)来修复它,然后再次运行迁移。希望这会有所帮助

于 2019-12-08T15:05:15.013 回答