Skip to content
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

Making existing fields translatable is not working with Django 2.1 #254

Open
floa93 opened this issue Sep 20, 2019 · 6 comments · May be fixed by #332
Open

Making existing fields translatable is not working with Django 2.1 #254

floa93 opened this issue Sep 20, 2019 · 6 comments · May be fixed by #332

Comments

@floa93
Copy link

floa93 commented Sep 20, 2019

Django 2.1.12
django-parler 2.0

Prerequisites:

  1. Create a new project and app
  2. Add a new model( to follow the migration guide at https://django-parler.readthedocs.io/en/stable/advanced/migrating.html):
    class MyModel(models.Model): name = models.CharField(max_length=123)
  3. Create and run the migration with makemigration

Making existing fields translatable(like explained in the documentation https://django-parler.readthedocs.io/en/stable/advanced/migrating.html)

  1. Change the model to :
class MyModel(TranslatableModel):
    name = models.CharField(max_length=123)

    translations = TranslatedFields(
          name=models.CharField(max_length=123),
    )

  1. Create the migration with makemigration
    -> Error that the name field already exists( see Error whikle making existing fields translatable - model already has a field #154 )
    -> rename the TranslatedField to translations_t and create the migration
  2. Run the migration with migrate ...
    -> AttributeError:

type object 'MyModel' has no attribute '_parler_meta'

Whatever you do, you always receive the attribute error that the model does not contain the parler_meta attribute. I need to make some fields translatable, that existed before, but unfortunately, I cannot make it work

Regards

@floa93
Copy link
Author

floa93 commented Sep 20, 2019

Here is the additional traceback to the error:

File "C:\Program Files\JetBrains\PyCharm 2019.1.1\helpers\pycharm\django_manage.py", line 52, in
run_command()
File "C:\Program Files\JetBrains\PyCharm 2019.1.1\helpers\pycharm\django_manage.py", line 46, in run_command
run_module(manage_file, None, 'main', True)
File "C:\Users\AppData\Local\Programs\Python\Python37-32\Lib\runpy.py", line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "C:\Users\AppData\Local\Programs\Python\Python37-32\Lib\runpy.py", line 96, in run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\AppData\Local\Programs\Python\Python37-32\Lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:/Users/projects/manage.py", line 19, in
execute_from_command_line(sys.argv)
File "C:\Users\virtualenvs\lib\site-packages\django\core\management_init
.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\virtualenvs\lib\site-packages\django\core\management_init
.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\virtualenvs\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\virtualenvs\lib\site-packages\django\core\management\base.py", line 353, in execute
output = self.handle(*args, **options)
File "C:\Users\virtualenvs\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\virtualenvs\lib\site-packages\django\core\management\commands\migrate.py", line 203, in handle
fake_initial=fake_initial,
File "C:\Users\virtualenvs\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\virtualenvs\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\virtualenvs\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\virtualenvs\lib\site-packages\django\db\migrations\migration.py", line 114, in apply
operation.state_forwards(self.app_label, project_state)
File "C:\Users\virtualenvs\lib\site-packages\django\db\migrations\operations\models.py", line 85, in state_forwards
list(self.managers),
File "C:\Users\virtualenvs\lib\site-packages\django\db\migrations\state.py", line 97, in add_model
self.reload_model(app_label, model_name)
File "C:\Users\virtualenvs\lib\site-packages\django\db\migrations\state.py", line 158, in reload_model
self._reload(related_models)
File "C:\Users\virtualenvs\lib\site-packages\django\db\migrations\state.py", line 191, in _reload
self.apps.render_multiple(states_to_be_rendered)
File "C:\Users\virtualenvs\lib\site-packages\django\db\migrations\state.py", line 306, in render_multiple
model.render(self)
File "C:\Users\virtualenvs\lib\site-packages\django\db\migrations\state.py", line 574, in render
return type(self.name, bases, body)
File "C:\Users\virtualenvs\lib\site-packages\django\db\models\base.py", line 299, in new
new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
File "C:\Users\virtualenvs\lib\site-packages\django\db\migrations\state.py", line 337, in register_model
self.do_pending_operations(model)
File "C:\Users\virtualenvs\lib\site-packages\django\apps\registry.py", line 420, in do_pending_operations
function(model)
File "C:\Users\virtualenvs\lib\site-packages\django\apps\registry.py", line 399, in apply_next_model
self.lazy_model_operation(next_function, *more_models)
File "C:\Users\virtualenvs\lib\site-packages\django\apps\registry.py", line 385, in lazy_model_operation
function()
File "C:\Users\virtualenvs\lib\site-packages\django\db\models\fields\related.py", line 316, in resolve_related_class
field.do_related_class(related, model)
File "C:\Users\virtualenvs\lib\site-packages\django\db\models\fields\related.py", line 387, in do_related_class
self.contribute_to_related_class(other, self.remote_field)
File "C:\Users\virtualenvs\lib\site-packages\parler\fields.py", line 54, in contribute_to_related_class
self.model.contribute_translations(cls)
File "C:\Users\virtualenvs\lib\site-packages\parler\models.py", line 939, in contribute_translations
base = shared_model._parler_meta
AttributeError: type object 'MyModel' has no attribute '_parler_meta'

@pbeyeler
Copy link

I am having the same issue with Django 1.11.20 and django-parler 2.0.

@pbeyeler
Copy link

@floa93: See #157 (comment) for a workaround.

@floa93
Copy link
Author

floa93 commented Sep 25, 2019

@pbeyeler thank you, your solution is working for me too and at least it is a temporary workaround

@lggwettmann
Copy link

Same here, would be great if this could be fixed :)

@milkomeda
Copy link

See my comment here for solution and clarificaton. #263 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants