我正在开发 Django 项目,并在运行
python manage.py migrate
命令时遇到问题。迁移过程失败并出现以下错误:
Traceback (most recent call last):
File "C:\Users\dell\Desktop\Django Project GMP\GMB-Django\gmb_project\manage.py", line 22, in <module>
main()
File "C:\Users\dell\Desktop\Django Project GMP\GMB-Django\gmb_project\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\dell\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
utility.execute()
File "C:\Users\dell\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\management\__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\dell\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\management\base.py", line 413, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\dell\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\management\base.py", line 459, in execute
output = self.handle(*args, **options)
File "C:\Users\dell\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\management\base.py", line 107, in wrapper
res = handle_func(*args, **kwargs)
File "C:\Users\dell\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\management\commands\migrate.py", line 303, in handle
pre_migrate_apps = pre_migrate_state.apps
File "C:\Users\dell\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\utils\functional.py", line 47, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\dell\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\db\migrations\state.py", line 565, in apps
return StateApps(self.real_apps, self.models)
File "C:\Users\dell\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\db\migrations\state.py", line 626, in __init__
self.render_multiple([*models.values(), *self.real_models])
File "C:\Users\dell\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\db\migrations\state.py", line 664, in render_multiple
model.render(self)
File "C:\Users\dell\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\db\migrations\state.py", line 957, in render
return type(self.name, bases, body)
File "C:\Users\dell\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\db\models\base.py", line 143, in __new__
new_class.add_to_class("_meta", Options(meta, app_label))
File "C:\Users\dell\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\db\models\base.py", line 371, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\dell\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\db\models\options.py", line 220, in contribute_to_class
raise TypeError(
TypeError: 'class Meta' got invalid attribute(s): index_together
如何解决此错误,需要进行哪些更改才能成功迁移?
如何解决此错误,需要进行哪些更改才能成功迁移? 在较新版本的 Django 中是否有替代 index_together 的方法?
在 Django 5.1 版本中,本文档中提到的
index_together
键已被删除。
https://docs.djangoproject.com/en/5.1/releases/5.1/
检查您正在使用的 Django 版本以及 Django 文档以供进一步参考。