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

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 #167

Open
NetOpsChic opened this issue May 17, 2024 · 1 comment
Labels
question Further information is requested type: bug

Comments

@NetOpsChic
Copy link

NetOpsChic commented May 17, 2024

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:

Screenshot 2024-05-17 112705
Screenshot 2024-05-17 112818

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.

@NetOpsChic NetOpsChic changed the title Issue in migrating .json file from Netbox 3.7.8 to Nautobot v2 using netbox impoter 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 Jul 15, 2024
@bryanculver
Copy link
Member

@NetOpsChic Can you try replicating with the latest version of Netbox Importer?

@bryanculver bryanculver added type: bug question Further information is requested labels Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested type: bug
Projects
None yet
Development

No branches or pull requests

2 participants