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

Migration fails on an uninitialised database #13636

Closed
peteeckel opened this issue Aug 31, 2023 · 2 comments
Closed

Migration fails on an uninitialised database #13636

peteeckel opened this issue Aug 31, 2023 · 2 comments

Comments

@peteeckel
Copy link
Contributor

NetBox version

v3.6.0

Python version

3.8

Steps to Reproduce

Freshly installed machine with Python 3.8 on CentOS 7.9.

  1. Create a new, empty NetBox database
  2. run manage.py migrate

Expected Behavior

Migrations are executed, resulting in a usable NetBox database instance

Observed Behavior

It seems #13116 is back:

(netbox) [root@dns netbox]# /opt/netbox/netbox/manage.py migrate 
Traceback (most recent call last):
  File "/opt/netbox/lib/python3.8/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "/opt/netbox/lib/python3.8/site-packages/psycopg/cursor.py", line 737, in execute
    raise ex.with_traceback(None)
psycopg.errors.UndefinedTable: relation "django_content_type" does not exist
LINE 1: ..."."app_label", "django_content_type"."model" FROM "django_co...
                                                             ^

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/netbox/netbox/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/netbox/lib/python3.8/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/opt/netbox/lib/python3.8/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/netbox/lib/python3.8/site-packages/django/core/management/base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/netbox/lib/python3.8/site-packages/django/core/management/base.py", line 458, in execute
    output = self.handle(*args, **options)
  File "/opt/netbox/lib/python3.8/site-packages/django/core/management/base.py", line 106, in wrapper
    res = handle_func(*args, **kwargs)
  File "/opt/netbox/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 100, in handle
    self.check(databases=[database])
  File "/opt/netbox/lib/python3.8/site-packages/django/core/management/base.py", line 485, in check
    all_issues = checks.run_checks(
  File "/opt/netbox/lib/python3.8/site-packages/django/core/checks/registry.py", line 88, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "/opt/netbox/lib/python3.8/site-packages/django/core/checks/urls.py", line 42, in check_url_namespaces_unique
    all_namespaces = _load_all_namespaces(resolver)
  File "/opt/netbox/lib/python3.8/site-packages/django/core/checks/urls.py", line 61, in _load_all_namespaces
    url_patterns = getattr(resolver, "url_patterns", [])
  File "/opt/netbox/lib/python3.8/site-packages/django/utils/functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/opt/netbox/lib/python3.8/site-packages/django/urls/resolvers.py", line 715, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/opt/netbox/lib/python3.8/site-packages/django/utils/functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/opt/netbox/lib/python3.8/site-packages/django/urls/resolvers.py", line 708, in urlconf_module
    return import_module(self.urlconf_name)
  File "/opt/netbox/lib64/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/opt/netbox/netbox/netbox/urls.py", line 9, in <module>
    from extras.plugins.urls import plugin_admin_patterns, plugin_patterns, plugin_api_patterns
  File "/opt/netbox/netbox/extras/plugins/urls.py", line 31, in <module>
    urlpatterns = import_string(f"{plugin_path}.urls.urlpatterns")
  File "/opt/netbox/lib/python3.8/site-packages/django/utils/module_loading.py", line 30, in import_string
    return cached_import(module_path, class_name)
  File "/opt/netbox/lib/python3.8/site-packages/django/utils/module_loading.py", line 15, in cached_import
    module = import_module(module_path)
  File "/opt/netbox/lib64/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/vagrant/netbox-dns/netbox_dns/urls.py", line 6, in <module>
    from netbox_dns.views import (
  File "/vagrant/netbox-dns/netbox_dns/views/__init__.py", line 1, in <module>
    from .view import *
  File "/vagrant/netbox-dns/netbox_dns/views/view.py", line 5, in <module>
    from netbox_dns.forms import ViewForm, ViewFilterForm, ViewImportForm, ViewBulkEditForm
  File "/vagrant/netbox-dns/netbox_dns/forms/__init__.py", line 4, in <module>
    from .record import *
  File "/vagrant/netbox-dns/netbox_dns/forms/record.py", line 25, in <module>
    class DynamicZoneChoiceField(DynamicModelChoiceField):
  File "/vagrant/netbox-dns/netbox_dns/forms/record.py", line 26, in DynamicZoneChoiceField
    filter = ZoneFilter()
  File "/opt/netbox/netbox/netbox/filtersets.py", line 284, in __init__
    content_types=ContentType.objects.get_for_model(self._meta.model)
  File "/opt/netbox/lib/python3.8/site-packages/django/contrib/contenttypes/models.py", line 52, in get_for_model
    ct = self.get(app_label=opts.app_label, model=opts.model_name)
  File "/opt/netbox/lib/python3.8/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/opt/netbox/lib/python3.8/site-packages/django/db/models/query.py", line 633, in get
    num = len(clone)
  File "/opt/netbox/lib/python3.8/site-packages/django/db/models/query.py", line 380, in __len__
    self._fetch_all()
  File "/opt/netbox/lib/python3.8/site-packages/django/db/models/query.py", line 1881, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/opt/netbox/lib/python3.8/site-packages/django/db/models/query.py", line 91, in __iter__
    results = compiler.execute_sql(
  File "/opt/netbox/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1562, in execute_sql
    cursor.execute(sql, params)
  File "/opt/netbox/lib/python3.8/site-packages/django/db/backends/utils.py", line 102, in execute
    return super().execute(sql, params)
  File "/opt/netbox/lib/python3.8/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
  File "/opt/netbox/lib/python3.8/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/opt/netbox/lib/python3.8/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "/opt/netbox/lib/python3.8/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/opt/netbox/lib/python3.8/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "/opt/netbox/lib/python3.8/site-packages/psycopg/cursor.py", line 737, in execute
    raise ex.with_traceback(None)
django.db.utils.ProgrammingError: relation "django_content_type" does not exist
LINE 1: ..."."app_label", "django_content_type"."model" FROM "django_co...
@peteeckel peteeckel added the type: bug A confirmed report of unexpected behavior in the application label Aug 31, 2023
@peteeckel
Copy link
Contributor Author

This seems to be related to a plugin (in this case netbox_dns) being installed. When I disable the plugin the migration works, when I then enable it afterwards and re-run the migration everything is OK.

@peteeckel
Copy link
Contributor Author

Never mind, the version of the plugin was an experimental branch. With the current production branch the problem does not occur, so this may be a plugin problem instead of one with NetBox itself.

@jeremystretch jeremystretch removed the type: bug A confirmed report of unexpected behavior in the application label Aug 31, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants