mardi 1 mars 2016

Getting django.db.utils.IntegrityError: insert or update on table violates foreign key constraint

I am using http://ift.tt/1tUn9Ai for audit logging. Everything was working fine but after migrating from SQLite to postgreSQL error started . . can someone tell me how to fix that. I do not want to disable the tracking . .

FK constraints:

Foreign-key constraints:
"girvi_transactionauditl_action_user_id_4e4ba6ed_fk_auth_user_id" FOREIGN KEY (action_user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED
"girvi_transactionauditlo_created_by_id_3f69a50a_fk_auth_user_id" FOREIGN KEY (created_by_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED
"girvi_transactionauditlo_updated_by_id_650e0db0_fk_auth_user_id" FOREIGN KEY (updated_by_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED
"girvi_transactionauditlog_credit_id_39e86678_fk_girvi_credit_id" FOREIGN KEY (credit_id) REFERENCES girvi_credit(id) DEFERRABLE INITIALLY DEFERRED
"girvi_transactionauditlog_packet_id_4b31e38d_fk_girvi_packet_id" FOREIGN KEY (packet_id) REFERENCES girvi_packet(id) DEFERRABLE INITIALLY DEFERRED

Full Traceback:

    [01/Mar/2016 21:06:11] ERROR [django.request:231] Internal Server Error: /delete_packet/469/
Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\django\db\backends\__init__.py", line 145, in _commit
    return self.connection.commit()
psycopg2.IntegrityError: insert or update on table "girvi_transactionauditlogentry" violates foreign key constraint "girvi_transactionauditlog_packet_id_4a1cc44e_fk_girvi_packet_id"
DETAIL:  Key (packet_id)=(469) is not present in table "girvi_packet".


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

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\django\core\handlers\base.py", line 111, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Python34\lib\site-packages\django\views\generic\base.py", line 69, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\Python34\lib\site-packages\django\utils\decorators.py", line 29, in _wrapper
    return bound_func(*args, **kwargs)
  File "C:\Python34\lib\site-packages\django\contrib\auth\decorators.py", line 22, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "C:\Python34\lib\site-packages\django\utils\decorators.py", line 25, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "C:\Apache24\apps\egirvi\egirvi\girvi\utils.py", line 15, in dispatch
    return super(LoginRequiredMixin, self).dispatch(*args, **kwargs)
  File "C:\Python34\lib\site-packages\django\views\generic\base.py", line 87, in dispatch
    return handler(request, *args, **kwargs)
  File "C:\Apache24\apps\egirvi\egirvi\girvi\views\deleteviews.py", line 101, in post
    super(DeletePacketView, self).post(request, *args, **kwargs)
  File "C:\Python34\lib\site-packages\django\views\generic\edit.py", line 259, in post
    return self.delete(request, *args, **kwargs)
  File "C:\Python34\lib\site-packages\django\views\generic\edit.py", line 254, in delete
    self.object.delete()
  File "C:\Python34\lib\site-packages\django\db\models\base.py", line 740, in delete
    collector.delete()
  File "C:\Python34\lib\site-packages\django\db\models\deletion.py", line 284, in delete
    sender=model, instance=obj, using=self.using
  File "C:\Python34\lib\site-packages\django\db\transaction.py", line 339, in __exit__
    connection.commit()
  File "C:\Python34\lib\site-packages\django\db\backends\__init__.py", line 176, in commit
    self._commit()
  File "C:\Python34\lib\site-packages\django\db\backends\__init__.py", line 145, in _commit
    return self.connection.commit()
  File "C:\Python34\lib\site-packages\django\db\utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "C:\Python34\lib\site-packages\django\utils\six.py", line 549, in reraise
    raise value.with_traceback(tb)
  File "C:\Python34\lib\site-packages\django\db\backends\__init__.py", line 145, in _commit
    return self.connection.commit()
django.db.utils.IntegrityError: insert or update on table "girvi_transactionauditlogentry" violates foreign key constraint "girvi_transactionauditlog_packet_id_4a1cc44e_fk_girvi_packet_id"
DETAIL:  Key (packet_id)=(469) is not present in table "girvi_packet".

I think SQLite doesn't enforce FK integrity but postgreSQL does. But how do I fix this ??

Aucun commentaire:

Enregistrer un commentaire