Error while adding "moderation" in INSTALLED_APPS

时间:2019-01-09 22:04:44

标签: python django python-3.x

I want to use django-moderation in my Django project. I have downloaded the app with pip3, the issue is when I added the app to INSTALLED_APPS, I have the following exception. Can you please advise how to get rid of this?

python3 manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x1024977b8>
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 112, in inner_run
    autoreload.raise_last_exception()
  File "/usr/local/lib/python3.7/site-packages/django/utils/autoreload.py", line 248, in raise_last_exception
    raise _exception[1]
  File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 327, in execute
    autoreload.check_errors(django.setup)()
  File "/usr/local/lib/python3.7/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 112, in populate
    app_config.import_models()
  File "/usr/local/lib/python3.7/site-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/local/lib/python3.7/site-packages/moderation/models.py", line 41, in <module>
    class ModeratedObject(models.Model):
  File "/usr/local/lib/python3.7/site-packages/moderation/models.py", line 43, in ModeratedObject
    editable=False)
TypeError: __init__() missing 1 required positional argument: 'on_delete

2 个答案:

答案 0 :(得分:1)

Django-moderation的最新版本是在2017年,因此它不支持Django 2。

对Django 2的拉取请求#169已被合并,但是从那时以来一直没有发布。您可以尝试在master分支上安装最新的提交,例如:

pip install git+git://github.com/dominno/django-moderation.git@565481f1832114da2d0c48b0c23977d4d3a9b914

(在您的情况下,您将使用pip3而不是pip,但是最好开始使用虚拟环境而不是系统Python。一旦激活了Python 3 virtual环境中,您使用pythonpip而不是python3pip3

答案 1 :(得分:0)

In your ModeratedObject model in moderation/models.py you have a model field ForeignKey with missing on_delete argument.

See example from documentation:

from django.db import models

class Car(models.Model):
    manufacturer = models.ForeignKey(
        'Manufacturer',
        on_delete=models.CASCADE,
    )

Additional documentation on on_delete argument is here.