0
Request Method: GET
Request URL:    http://localhost:8000/blog/blog-title/
Django Version: 1.10.8
Exception Type: ValueError
Exception Value:    
'title_en' is not in list
Exception Location: /lib/python3.6/site-packages/django/db/models/query.py in __init__, line 1715
Python Executable:  /bin/python
Python Version: 3.6.5

after installing django-modeltranslation i am getting this error on my django site. I have tried adding fields in translationOptions. Also tried makemigration and migrations. This adds the title_en in table however it's not rendering the blog on the front. Before adding django-modeltranslation the blogs were being rendered properly without any error.

1 Answers1

0

When you add model-translation to existing models, which already contain data, the data is still stored in the original column (e.g. title) but not copied to the new default language column title_en.

So if you're migrating existing data, after makemigrations and migrate you should also run update_translation_fields which will copy any existing values into the empty default language columns.

You can run this multiple times (when adding translation to other models later), it only copies values when the _en field is empty.

dirkgroten
  • 20,112
  • 2
  • 29
  • 42
  • Note that for your specific `ValueError` above, you need to show us the code of the line where the error occurs, seems you're hard-coding the field name `title` somewhere and it's now replaced with `title_en` (or `title_fr` if the user sets his language to French) so you have to be careful about this. – dirkgroten Sep 15 '18 at 13:08