英文:
How can I delete ManyToManyField on Django Model (used in Wagtail Page inheritor)?
问题
I have such field:
from wagtail.models import Page
class MyModel(Page):
...
many_to_many_field = models.ManyToManyField(ToClass, blank=False, related_name='+', verbose_name=_("My models"))
...
I tried simply to comment it like this:
from wagtail.models import Page
class MyModel(Page):
...
# many_to_many_field = models.ManyToManyField(ToClass, blank=False, related_name='+', verbose_name=_("My models"))
But I've got 'django.core.exceptions.FieldError' while was executing 'python manage.py makemigrations':
Traceback (most recent call last):
File "D:\projects\myapp\manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "D:\Python311\Lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
utility.execute()
File "D:\Python311\Lib\site-packages\django\core\management\__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\Python311\Lib\site-packages\django\core\management\base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "D:\Python311\Lib\site-packages\django\core\management\base.py", line 443, in execute
self.check()
File "D:\Python311\Lib\site-packages\django\core\management\base.py", line 475, in check
all_issues = checks.run_checks(
^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\django\core\checks\registry.py", line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\wagtail\admin\checks.py", line 70, in get_form_class_check
if not issubclass(edit_handler.get_form_class(), WagtailAdminPageForm):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\wagtail\admin\panels\base.py", line 162, in get_form_class
return get_form_for_model(
^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\wagtail\admin\panels\base.py", line 48, in get_form_for_model
return metaclass(class_name, tuple(bases), form_class_attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\wagtail\admin\forms\models.py", line 124, in __new__
new_class = super(WagtailAdminModelFormMetaclass, cls).__new__(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
new_class = super().__new__(mcs, name, bases, attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\modelcluster\forms.py", line 259, in __new__
new_class = super().__new__(cls, name, bases, attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\django\forms\models.py", line 327, in __new__
raise FieldError(message)
django.core.exceptions.FieldError: Unknown field(s) (many_to_many_field) specified for MyModel
What is wrong? How can I delete it?
英文:
I have such field:
from wagtail.models import Page
class MyModel(Page):
...
many_to_many_field = models.ManyToManyField(ToClass, blank=False, related_name='+', verbose_name=_("My models"))
...
I tried simply to comment it like this:
from wagtail.models import Page
class MyModel(Page):
...
# many_to_many_field = models.ManyToManyField(ToClass, blank=False, related_name='+', verbose_name=_("My models"))
But I've got 'django.core.exceptions.FieldError' while was executing 'python manage.py makemigrations':
Traceback (most recent call last):
File "D:\projects\myapp\manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "D:\Python311\Lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
utility.execute()
File "D:\Python311\Lib\site-packages\django\core\management\__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\Python311\Lib\site-packages\django\core\management\base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "D:\Python311\Lib\site-packages\django\core\management\base.py", line 443, in execute
self.check()
File "D:\Python311\Lib\site-packages\django\core\management\base.py", line 475, in check
all_issues = checks.run_checks(
^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\django\core\checks\registry.py", line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\wagtail\admin\checks.py", line 70, in get_form_class_check
if not issubclass(edit_handler.get_form_class(), WagtailAdminPageForm):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\wagtail\admin\panels\base.py", line 162, in get_form_class
return get_form_for_model(
^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\wagtail\admin\panels\base.py", line 48, in get_form_for_model
return metaclass(class_name, tuple(bases), form_class_attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\wagtail\admin\forms\models.py", line 124, in __new__
new_class = super(WagtailAdminModelFormMetaclass, cls).__new__(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
new_class = super().__new__(mcs, name, bases, attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\modelcluster\forms.py", line 259, in __new__
new_class = super().__new__(cls, name, bases, attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\site-packages\django\forms\models.py", line 327, in __new__
raise FieldError(message)
django.core.exceptions.FieldError: Unknown field(s) (many_to_many_field) specified for MyModel
What is wrong? How can I delete it?
答案1
得分: 0
你的代码中某处仍然引用了已删除的many_to_many_field
- 很可能它仍然在content_panels
的定义中列出 - 在继续之前,你需要移除这个引用。
英文:
You have a reference to the deleted many_to_many_field
somewhere else in your code - most likely, it's still listed in the content_panels
definition - and you'll need to remove this reference before you can proceed.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论