我正在尝试使用ManytoManyField,但是每当我运行makemigrations时,Django都会返回此错误:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/user/app/lib/python3.5/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/user/app/lib/python3.5/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/home/user/app/lib/python3.5/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/user/app/lib/python3.5/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/user/app/lib/python3.5/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/home/user/app/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/home/user/app/bin/app/app_main/models.py", line 7, in <module>
class user(AbstractUser):
File "/home/user/app/bin/app/app_main/models.py", line 8, in user
blocking = models.ManytoManyField('self', symmetrical=False)
AttributeError: module 'django.db.models' has no attribute 'ManytoManyField'
为什么会这样?我已经看过其他类似问题的SO问题,但它们通常源于将其称为“ ManyToManyField”而不是“ models.ManyToManyField”的编码器。预先感谢您的帮助。
答案 0 :(得分:1)
您在这里打错字。 应该是
blocking = models.ManyToManyField('self', symmetrical=False)