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

When upgrading on Python 3, the user is prompted to create new migrations #1220

Closed
jeremystretch opened this issue May 24, 2017 · 1 comment
Labels
type: bug A confirmed report of unexpected behavior in the application

Comments

@jeremystretch
Copy link
Member

Issue type: Bug report

Python version: 3.x
NetBox version: 2.0.3

When running NetBox on Python 3, applying database migrations will report a warning about unreflected migrations and prompt the user to create new migrations:

root@netbox-test:/opt/netbox/netbox# ./manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, circuits, contenttypes, dcim, extras, ipam, secrets, sessions, tenancy, users
Running migrations:
  No migrations to apply.
  Your models have changes that are not yet reflected in a migration, and so won't be applied.
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

This is due to a semantic difference in how Python 2 and Python 3 treat strings differently. This warning can be safely ignored, however a user might understandably proceed with creating new migrations as instructed.

The new migrations will not cause data corruption, however their presence may introduce errors. For example:

$ sudo python3 manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, circuits, contenttypes, dcim, extras, ipam, secrets, sessions, tenancy, users
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/migrate.py", line 163, in handle
    pre_migrate_state = executor._create_project_state(with_applied_migrations=True)
  File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/executor.py", line 81, in _create_project_state
    migration.mutate_state(state, preserve=False)
  File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/migration.py", line 92, in mutate_state
    operation.state_forwards(self.app_label, new_state)
  File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/operations/fields.py", line 199, in state_forwards
    state.models[app_label, self.model_name_lower].fields
KeyError: ('dcim', 'module')

Users are advised to simply delete any migrations they have created (those which are not present in the master branch of the NetBox repository), after which an upgrade can be performed successfully. The next release will include a set of migrations converting all model Python 2 bytestrings to Unicode to ensure users are no longer prompted to create migrations.

@jeremystretch jeremystretch added the type: bug A confirmed report of unexpected behavior in the application label May 24, 2017
@jeremystretch
Copy link
Member Author

This issue was addressed in f21c6bc and 138cbf9. Once the new set of migrations has been applied, the warning should no longer appear after future migrations.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

1 participant