question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to do a data migration from existing field to default language?

See original GitHub issue

models.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:closed
  • Created 8 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

12reactions
RamiAhmedcommented, Jul 10, 2015

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!

5reactions
RamiAhmedcommented, Jul 6, 2015

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found