Error while creating device: duplicate key value violates unique constraint "dcim_device_pkey" #7405
-
NetBox versionv2.11.12 Python version3.8 Steps to ReproduceI first added some new devices using netbox/manage.py nbshell
Now when I try to create a new device from the web interface, any device, I get this error:
Expected BehaviorNo error at all! Observed BehaviorMy guess is that I incorrectly created those devices using the netbox shell. What's wrong in those code lines? How can I fix the primary key inconsistence? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
You are manually assigning the id so the id sequence doesn't get updated, you should not do that. Just remove |
Beta Was this translation helpful? Give feedback.
-
Ok, I'll do. But then why the doc shows an example like this? Any idea on how can I fix the current DB mess? |
Beta Was this translation helpful? Give feedback.
-
A vid on a VLAN is not the same as the autoincrementing id that's present on all models. You should be able to fix it by either deleting the devices you created or accessing postgres database and altering the sequence. Something like this:
Replace 999 with the id of the highest numbered device you currently have. |
Beta Was this translation helpful? Give feedback.
-
Oh crap... I'm retar*!@ It's now working wonderfully. Thanks @kkthxbye-code |
Beta Was this translation helpful? Give feedback.
A vid on a VLAN is not the same as the autoincrementing id that's present on all models.
You should be able to fix it by either deleting the devices you created or accessing postgres database and altering the sequence. Something like this:
ALTER SEQUENCE dcim_device_id_seq RESTART WITH 999;
Replace 999 with the id of the highest numbered device you currently have.