nautobot-app-netbox-importer
nautobot-app-netbox-importer copied to clipboard
Issue: 'django.db.utils.IntegrityError: insert or update on table "dcim_device" violates foreign key constraint' in migrating .json file from Netbox 3.7.8 to Nautobot v2 using netbox impoter
I am reaching out regarding an issue encountered during the migration process from NetBox to Nautobot as I am pretty new in this domain. Allow me to provide detailed insights into the situation and the steps taken thus far.
Background: In the migration process, the data from NetBox has been exported into a .dump file. Subsequently, this data was loaded into NetBox, and a JSON file was extracted. The intention is to transfer this data into Nautobot, facilitating a seamless transition between the two platforms.
Current Challenge: During the migration process into Nautobot, a hurdle has arisen due to the requirement of the "--bypass data validation" flag. While attempting to execute the migration without utilizing this flag, the process encounters constraints, impeding the successful transfer of data.
Netbox v3.7.8 Nautobot v2.X
Issue:
Error sys.exit(main()) File "/opt/nautobot/lib/python3.10/site-packages/nautobot/core/cli/__init__.py", line 293, in main execute_from_command_line([sys.argv[0], *unparsed_args]) File "/opt/nautobot/lib/python3.10/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line utility.execute() File "/opt/nautobot/lib/python3.10/site-packages/django/core/management/__init__.py", line 413, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/opt/nautobot/lib/python3.10/site-packages/django/core/management/base.py", line 354, in run_from_argv self.execute(*args, **cmd_options) File "/opt/nautobot/lib/python3.10/site-packages/django/core/management/base.py", line 398, in execute output = self.handle(*args, **options) File "/opt/nautobot/lib/python3.10/site-packages/nautobot_netbox_importer/management/commands/import_netbox.py", line 89, in handle adapter.import_to_nautobot() File "/opt/nautobot/lib/python3.10/site-packages/nautobot_netbox_importer/diffsync/adapters/netbox.py", line 97, in import_to_nautobot self._atomic_import() File "/usr/lib/python3.10/contextlib.py", line 78, in inner with self._recreate_cm(): File "/opt/nautobot/lib/python3.10/site-packages/django/db/transaction.py", line 246, in __exit__ connection.commit() File "/opt/nautobot/lib/python3.10/site-packages/django/utils/asyncio.py", line 33, in inner return func(*args, **kwargs) File "/opt/nautobot/lib/python3.10/site-packages/django/db/backends/base/base.py", line 266, in commit self._commit() File "/opt/nautobot/lib/python3.10/site-packages/django/db/backends/base/base.py", line 241, in _commit with self.wrap_database_errors: File "/opt/nautobot/lib/python3.10/site-packages/django/db/utils.py", line 90, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/opt/nautobot/lib/python3.10/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_device" violates foreign key constraint "dcim_device_primary_ip4_id_2ccd943a_fk_ipam_ipaddress_id" DETAIL: Key (primary_ip4_id)=(some UUID) is not present in table "ipam_ipaddress".
Is there anything I am missing out? Steps that were taken:
sudo -u postgres psql -c 'drop database netbox'
sudo -u postgres psql -c 'create database netbox'
sudo -u postgres psql -c 'grant all privileges on database netbox to netbox
sudo -u postgres psql -c 'grant all privileges on database netbox to netbox'
sudo -u postgres psql netbox < netbox-postgresql.dump
sudo /opt/netbox/upgrade.sh
touch /tmp/netbox_data.json
cd /opt/netbox/netbox/
python3 manage.py dumpdata --traceback --format=json --exclude admin.logentry --exclude sessions.session --exclude extras.ObjectChange --exclude extras.Script --exclude extras.Report --exclude django_rq --exclude extras.imageattachment > /tmp/netbox_data.json
On Nautobot instance the JSON file was transffered using scp and data was dumped:
nautobot-server import_netbox --dry-run netbox_data.json
Any suggestion is appreciated. Thank you in advance.