python - Django oauth 工具包 : migrate gives type error - getting started tutorial

标签 python django-rest-framework django-oauth

我正在尝试遵循来自以下位置的 django oauth 工具包入门教程:

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

当我运行migrate时,出现以下错误:

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'

如有任何帮助,我们将不胜感激。

完整的堆栈跟踪

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'

最佳答案

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

关于python - Django oauth 工具包 : migrate gives type error - getting started tutorial,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47248596/

相关文章:

python - 如何使用 Anaconda 安装 Django Rest Framework?

django - 无法为API设置“DEFAULT_AUTHENTICATION_CLASSES”导入“oauth2_provider.ext.rest_framework.OAuth2Authentication”

python - Django OAuth - 分离资源和授权服务器

python - wxPython 上的 IPython

python - 如何逐层打印二叉树

django - CORS 在 dockerized Django REST + Angular 项目中被阻止

python - 获取 Django Rest Framework 中的 session 时间

python - Django Rest Framework 和 OAuth2 Toolkit 的额外保护层

python - 如果数字大于或等于 772000000000000,为什么我的 python 代码会产生无限循环?

python - cygdb导入错误: No module named 'Cython'