Error: insert or update on table "storageadmin_networkdevice" violates foreign key constraint

Brief description of the problem

I went to the “Network” on the web-UI and it showed this issue.

Detailed step by step instructions to reproduce the problem

I don’t know how it got there

Error Traceback provided on the Web-UI

Traceback (most recent call last): File "/opt/rockstor/src/rockstor/rest_framework_custom/generic_view.py", line 41, in _handle_exception yield File "/opt/rockstor/src/rockstor/storageadmin/views/network.py", line 201, in get_queryset self._refresh_devices() File "/opt/rockstor/eggs/Django-1.8.16-py2.7.egg/django/utils/decorators.py", line 145, in inner return func(*args, **kwargs) File "/opt/rockstor/eggs/Django-1.8.16-py2.7.egg/django/db/transaction.py", line 225, in __exit__ connection.commit() File "/opt/rockstor/eggs/Django-1.8.16-py2.7.egg/django/db/backends/base/base.py", line 173, in commit self._commit() File "/opt/rockstor/eggs/Django-1.8.16-py2.7.egg/django/db/backends/base/base.py", line 142, in _commit return self.connection.commit() File "/opt/rockstor/eggs/Django-1.8.16-py2.7.egg/django/db/utils.py", line 98, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) File "/opt/rockstor/eggs/Django-1.8.16-py2.7.egg/django/db/backends/base/base.py", line 142, in _commit return self.connection.commit() IntegrityError: insert or update on table "storageadmin_networkdevice" violates foreign key constraint "connection_id_refs_id_1db23ec5" DETAIL: Key (connection_id)=(2) is not present in table "storageadmin_networkconnection".

Hi @Tony_Cristiano,

We’ve seen that error seldomly, but unfortunately it’s a difficult one to pinpoint and we haven’t been able to get a reproducer for it. Previous reports of it have mentioned that it goes away by itself, so would you let us know whether or not you are still enountering it, or noticing anything not functional as a result?

If you are still affected by it, would you be willing to run a few commands in an attempt to see what is causing this on your end? It would be great if we could get more information and maybe even figure out why you are experiencing this.

What is happening relates to the update of network connections and devices that occur when one visits the System > Network page:

As you can see above, this procedure essentially first fetches all devices information currently stored in Rockstor’s database, then compares it to what can be currently detected on the system. All that is in the database but not on the system is deleted from the database, and all that is currently on the system but not in the database is stored in the database.
I believe you are encountering an error in the latter case, as the error you see seems to originate when the following line is run:

For instance, it seems that you have one network device that seems to not have a corresponding connection, while it used to have one…

Would you be able to provide more information regarding your network setup, by the way? Have you made any change to it (added/removed anything network-related, hardware or software-wise)?

Sorry I’m unable to provide more help at the moment, but with some more digging we can hopefully figure that one out.

1 Like

I made a change to IP address issued by the router. Used to be 192.168.1.22 and now is set to 192.168.1.31

I haven’t seen the message anymore, only saw it once. Perhaps it’s fixed now. I don’t want to have corrupt Rockstor database that’s going to cause havoc later on.

1 Like

I’m glad you seem all fixed now, thanks a lot for letting us know; it actually does comfort me as I believe this is more a little annoyance than an actual issue…

I do believe chances are it’s all fine now as all networking-related settings are updated and synced to what is detected on the system upon every visit of the System > Network page. As a result, it is not that easy to get it out of sync.
Incidentely, this is also what cause the error you saw, as my guess is that it was in the process of being updated, explaining why it had a network device in the database with an non-existent connection. There’s room for improvement on how to deal with this sort of things, but fortunately you provided some starting material. Indeed:

Hopefully we’ll be able to get precise steps to reproduce the error you saw thanks to that and make the necessary fixes.

Thanks a lot! I do believe you should all fine now, but don’t hesitate to let us know if you notice anything odd.