-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Translated models can't be used in datamigration #157
Comments
I have the same issue, I also can't use it in data migrations and I have the following traceback:
|
I'm quite surprised to see This doesn't activate our metaclass, so Which Django version have you used? |
I'm using Django 1.8 Migrations where created automatically. And this is what I have. When I change it as you said to use The only workaround is to remove |
Faced the same issue when trying to create default objects during migration and also having the same bases. Im using Django 1.10. |
I'm working a solution which involves refactoring the base class. Can't promise any ETA, though, but I'll keep you updated |
Same problem using 1.10 |
I run into the same issue, also using Django 1.10. @yakky , any news on that ETA ;)? |
I experienced the exact same problem.
Here is the full code:
This way you will not need to modify any migration files. |
@JacoboCarbo is your model the same as the ModelTranslation? |
…ions. Adds a TranslationsForeignKey field type that contributes translations to the target model.
So someone in #django encountered this issue and I decided to dive in. The core of the issue is that Django does not add abstract base models to the I've played with a few solutions, and by far the cleanest is to add a new field type subclassing ForeignKey to handle the link between the translatable model and the translations model. Since this is a concrete field (backed by a db column), the field is added to the migrations by Django, allowing it to run One issue is that migrations do not have any operation to change the bases of a model. To add support for translations in data migrations, the CreateModel operation for the translations model has to be edited manually to add |
…ions. Adds a TranslationsForeignKey field type that contributes translations to the target model.
Any chance we can get a release that includes this fix? |
same issue using used from django.db import models
from parler.models import TranslatableModel, TranslatedFields
from webapp.core.models.base_model import BaseModel
class MyModel(models.Model):
class Meta:
verbose_name = 'My Model'
verbose_name_plural = 'My Model'
title = models.CharField(max_length=50) to new Model: from django.db import models
from parler.models import TranslatableModel, TranslatedFields
from webapp.core.models.base_model import BaseModel
class MyModel(TranslatableModel):
class Meta:
verbose_name = 'My Model'
verbose_name_plural = 'My Model'
translations = TranslatedFields(
title=models.CharField("Title", max_length=50)
)
by manually changing the migration File from: bases=(parler.models.TranslatedFieldsModelMixin, models.Model), to bases=(parler.models.TranslatableModel, models.Model), migrate is doing it's job. |
I was able to make this work by replacing |
I also wonder about that. This really needs a good test to sort that out, or a migration file that demos the problem. This could become part of the test suite too. For v2.0.1 I've only changed the |
@vdboor I was also encountering the I could work around it by using the Constructing the translations model manually method from the docs. And in fact, this seems to me like a more idiomatic way to achieve this ("explicit is better than implicit"). It's also pretty simple and not a large amount of boilerplate either. Do you think this method might be the default way to achieve this going forward? |
@vdboor, I've encountered the Here's my traceback:
I've attached both files: 0011_auto_20200207_1306.txt I want to translate existing models. |
See my comment here for solution and clarificaton. #263 (comment) |
Probably similar to #100
When I try to use translated models in data migration I have an error when I try to create new instance and save it. The error is:
Also when I try to query translated models with specific methods to parler's
TranslatableManager
it raisesAttributeError
.In the initial migration when model is created in
migrations.CreateModel
step I see that bases are defined like that:The text was updated successfully, but these errors were encountered: