ionos-cloud/dim

dim has foreign key violation when deleting users

miesi opened this issue · 0 comments

miesi commented

When looking through the innodb status, I found out, that dim has problems deleting users that have favorite views.

------------------------
LATEST FOREIGN KEY ERROR
------------------------
2020-02-05 14:03:08 7f09f3ad5b00 Transaction:
TRANSACTION 1991661606, ACTIVE 7 sec updating or deleting, thread declared inside InnoDB 4999
mysql tables in use 4, locked 4
45 lock struct(s), heap size 13864, 161 row lock(s), undo log entries 116
MySQL thread id 1601739, OS thread handle 0x7f09f3ad5b00, query id 4649885179 dimmw-output-de-kae-bs01.server.lan 10.76.136.192 dim updating
DELETE FROM user WHERE user.id = 2501
Foreign key constraint fails for table "netdot"."favoritezoneview":
,
  CONSTRAINT "favoritezoneview_ibfk_2" FOREIGN KEY ("user_id") REFERENCES "user" ("id")
Trying to delete or update in parent table, in index "PRIMARY" tuple:
DATA TUPLE: 9 fields;
 0: len 8; hex 80000000000009c5; asc         ;;
 1: len 6; hex 000076b65826; asc   v X&;;
 2: len 7; hex 3500001d811d6f; asc 5     o;;
 3: len 8; hex 8000000000000003; asc         ;;
 4: len 10; hex 616c656b6f65686c6572; asc alekoehler;;
 5: len 4; hex 81447080; asc  Dp ;;
 6: len 18; hex 4bc3b6686c65722c20416c6578616e646572; asc K  hler, Alexander;;
 7: len 4; hex 814896ba; asc  H  ;;
 8: SQL NULL;

But in child table "netdot"."favoritezoneview", in index "user_id", there is a record:
PHYSICAL RECORD: n_fields 2; compact format; info bits 0
 0: len 8; hex 80000000000009c5; asc         ;;
 1: len 8; hex 80000000000060ec; asc       ` ;;

We should either switch the foreign key relation to be cascaded on delete or remove the favorite views before trying to delete the user.