nautobot-app-netbox-importer icon indicating copy to clipboard operation
nautobot-app-netbox-importer copied to clipboard

Handle Foreign key contraints during import

Open harsh-kotak opened this issue 3 months ago • 1 comments

Environment

  • Python version: 3.9.18
  • Nautobot version: 2.2.0
  • nautobot-netbox-importer version: 2.0.0

Netbox data import

Foreign key contraints

I am trying to migrate to nautobot from netbox 3.6.7. The import fails with the below error. Is there a way to narrow down the issue to a particular Netbox cable ID rather than a nautobot UUID which does not help. We have hundreds of devices and associated cable info in netbox so not sure how to navigate this. Any inputs would be appreciated.

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

Traceback (most recent call last):
  File "/opt/nautobot/bin/nautobot-server", line 8, in <module>
    sys.exit(main())
  File "/opt/nautobot/lib64/python3.9/site-packages/nautobot/core/cli/__init__.py", line 286, in main
    execute_from_command_line([sys.argv[0], *unparsed_args])
  File "/opt/nautobot/lib64/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/opt/nautobot/lib64/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/nautobot/lib64/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/nautobot/lib64/python3.9/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/opt/nautobot/lib64/python3.9/site-packages/nautobot_netbox_importer/management/commands/import_netbox.py", line 89, in handle
    adapter.import_to_nautobot()
  File "/opt/nautobot/lib64/python3.9/site-packages/nautobot_netbox_importer/diffsync/adapters/netbox.py", line 97, in import_to_nautobot
    self._atomic_import()
  File "/usr/lib64/python3.9/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/opt/nautobot/lib64/python3.9/site-packages/django/db/transaction.py", line 246, in __exit__
    connection.commit()
  File "/opt/nautobot/lib64/python3.9/site-packages/django/utils/asyncio.py", line 33, in inner
    return func(*args, **kwargs)
  File "/opt/nautobot/lib64/python3.9/site-packages/django/db/backends/base/base.py", line 266, in commit
    self._commit()
  File "/opt/nautobot/lib64/python3.9/site-packages/django/db/backends/base/base.py", line 242, in _commit
    return self.connection.commit()
  File "/opt/nautobot/lib64/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/opt/nautobot/lib64/python3.9/site-packages/django/db/backends/base/base.py", line 242, in _commit
    return self.connection.commit()
django.db.utils.IntegrityError: insert or update on table "dcim_consoleport" violates foreign key constraint "dcim_consoleport_cable_id_a9ae5465_fk_dcim_cable_id"
DETAIL:  Key (cable_id)=(b74c4439-6217-5ebf-9e8f-d8ae8ac1c497) is not present in table "dcim_cable".

harsh-kotak avatar Apr 03 '24 21:04 harsh-kotak