简体   繁体   中英

Django model translation - cannot import name 'Constraint'

I want to translate content of my models fields with django-modeltranslation .

When i run one of these:

python manage.py makemigrations
python manage.py runserver

I get ImportError: cannot import name 'Constraint'

Here is the traceback of the 'makemigrations'

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/mat/Desktop/python/pmm/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "/home/mat/Desktop/python/pmm/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 324, in execute
    django.setup()
  File "/home/mat/Desktop/python/pmm/venv/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/mat/Desktop/python/pmm/venv/lib/python3.4/site-packages/django/apps/registry.py", line 115, in populate
    app_config.ready()
  File "/home/mat/Desktop/python/pmm/venv/lib/python3.4/site-packages/django/contrib/admin/apps.py", line 22, in ready
    self.module.autodiscover()
  File "/home/mat/Desktop/python/pmm/venv/lib/python3.4/site-packages/django/contrib/admin/__init__.py", line 26, in autodiscover
    autodiscover_modules('admin', register_to=site)
  File "/home/mat/Desktop/python/pmm/venv/lib/python3.4/site-packages/django/utils/module_loading.py", line 50, in autodiscover_modules
    import_module('%s.%s' % (app_config.name, module_to_search))
  File "/home/mat/Desktop/python/pmm/venv/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/mat/Desktop/python/pmm/venv/lib/python3.4/site-packages/modeltranslation/admin.py", line 20, in <module>
    from modeltranslation.translator import translator
  File "/home/mat/Desktop/python/pmm/venv/lib/python3.4/site-packages/modeltranslation/translator.py", line 12, in <module>
    from modeltranslation.manager import (MultilingualManager, MultilingualQuerysetManager,
  File "/home/mat/Desktop/python/pmm/venv/lib/python3.4/site-packages/modeltranslation/manager.py", line 19, in <module>
    from django.db.models.sql.where import Constraint
ImportError: cannot import name 'Constraint'

I use django1.9 and the latest django-modeltranslation.

If you cant help me with error, please recommand any other model translation app.

I have came across some of them:

django-multilingual-ds9

django-dbgettext

django-transmeta

But they seem to be no longer supported. Do you know if any of these works , or do you know about any other working solution ?

If that matters i have to admit i use django-rosette

I found other app for model translation, django-hvad .

Works like a charm, have full django1.9 support, is easy to implement and is translator-friendly.

Are you sure you are using the latest django-modeltranslation? The issue was reported a while ago ( https://github.com/deschler/django-modeltranslation/issues/349 ) and already fixed in version 0.11rc1 ( https://pypi.python.org/pypi/django-modeltranslation/0.11rc1 ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM