How to do a data migration from existing field to default language?
See original GitHub issuemodels.py
from django.db import models
class Service(models.Model):
name = models.CharField(max_length=100)
url = models.CharField(max_length=300)
def __str__(self):
return self.name
translation.py
from modeltranslation.translator import translator, TranslationOptions
from portal.models import Service
class ServiceTranslationOptions(TranslationOptions):
fields = ('name', 'description')
translator.register(Service, ServiceTranslationOptions)
admin.py
from django.contrib import admin
from modeltranslation.admin import TabbedTranslationAdmin
from portal.models import Service
class ServiceAdmin(TabbedTranslationAdmin):
pass
admin.site.register(Service, ServiceAdmin)
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Making existing fields translatable - django-parler
To make existing fields translatable, 3 migration steps are needed: Create the translation table, keep the existing columns; Copy the data from the...
Read more >Database Migration: What It Is and How to Do It - CloudBees
Option 1: Use a Framework/Language-Dependent Library Depending on the setup, you can even swap out the native database migration for other ...
Read more >Migration works with default language but not with translation
I installed version 8.x-1.0-beta7 on my website which has English and French versions, then I followed all the instructions to migrate image ...
Read more >Django Migrations Add Field with Default as Function of Model
Alter the field (with AlterField ) to make it not nullable (like the above, with no default). So you end up with something...
Read more >General Data for Data Migration/Default Rules
Rule ID Procedure Name Description
ADDOBJID MIGRATE% REPLICATION Create extra detail for OBJID
BUILDTRIGGERIF REPLICATION Build IF‑statement for updateable columns
CALLEXTPROC CREATE_OUTPUT_FILE Call external procedure after...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Actually I found the answer in the excellent documentation: http://django-modeltranslation.readthedocs.org/en/latest/commands.html#the-update-translation-fields-command
Using the command
update_translation_fields
, all my problems were solved. Thanks!This question is quite relevant for me as well.
We have an existing database in english. When I run makemigrations with translations enabled, all the fields marked for translation are cleared so that all translation fields are empty. This is unacceptable for us.
We need to be able to use the current data in the database for the language marked as default. Also, we would not want to have to fill out all the “_en” fields, as we already have it in english. Frankly, I’m surprised that the “_en” columns were added, considering that it should just use whatever is presently there in the database for that model?
Hoping for a speedy resolution to this issue!
Python 2.7, Django 1.8, Heroku hosted