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

Django 1.11 and Python 3.6 causes error in migration #38

Closed
tim-schilling opened this issue Apr 13, 2017 · 4 comments
Closed

Django 1.11 and Python 3.6 causes error in migration #38

tim-schilling opened this issue Apr 13, 2017 · 4 comments
Assignees
Milestone

Comments

@tim-schilling
Copy link
Contributor

tim-schilling commented Apr 13, 2017

We recently upgraded to django 1.11 and python 3.6. This caused a migration that should have ran without any problem. However, due to django's field internals keeping values as bytes rather than unicode this errors out in _get_python_and_db_repr as there is no handler for a bytes type.

Stacktrace from migration:

 File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/project/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "/project/lib/python3.6/site-packages/django/core/management/__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/project/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/project/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/project/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "/project/lib/python3.6/site-packages/django/db/migrations/executor.py", line 115, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/project/lib/python3.6/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/project/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/project/lib/python3.6/site-packages/django/db/migrations/migration.py", line 129, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/project/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 215, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/project/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 513, in alter_field
    old_db_params, new_db_params, strict)
  File "/project/lib/python3.6/site-packages/django/db/backends/postgresql/schema.py", line 112, in _alter_field
    new_db_params, strict,
  File "/project/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 602, in _alter_field
    old_default = self.effective_default(old_field)
  File "/project/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 206, in effective_default
    default = field.get_default()
  File "/project/lib/python3.6/site-packages/timezone_field/fields.py", line 92, in get_default
    return self._get_python_and_db_repr(value)[0]
  File "/project/lib/python3.6/site-packages/timezone_field/fields.py", line 118, in _get_python_and_db_repr
    raise ValidationError("Invalid timezone '%s'" % value)
django.core.exceptions.ValidationError: ["Invalid timezone 'b'UTC''"]

PR to follow.

tim-schilling added a commit to tim-schilling/django-timezone-field that referenced this issue Apr 13, 2017
@mikekeda
Copy link

mikekeda commented Jun 7, 2017

I have Django 1.11.2 and Python 3.4.3
python manage.py makemigrations dosen't see the field

"No changes detected"

@tim-schilling
Copy link
Contributor Author

Did you upgrade to that environment then run makemigrations?

tim-schilling added a commit to tim-schilling/django-timezone-field that referenced this issue Jun 7, 2017
@TurboBelka
Copy link

Does it work now with Django 1.11?

@ftvkun
Copy link

ftvkun commented Feb 13, 2018

I fixed that by changing fields.TimeZoneField(default=b'XXX') to fields.TimeZoneField(default='XXX') in our old migrations

@mfogel mfogel self-assigned this Feb 28, 2018
@mfogel mfogel added this to the 2.1 milestone Mar 1, 2018
@mfogel mfogel closed this as completed in #39 Mar 1, 2018
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

No branches or pull requests

5 participants