Skip to main content
 首页 » 编程设计

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

2024年10月01日26lexus

我正在尝试遵循 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 除外)然后再次运行迁移来修复它。希望这会有所帮助