Bugzilla – Attachment 195123 Details for
Bug 42068
Update on bug 26993 breaks items deletions with a corrupted foreign key
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 42068: Bug 26993 (follow-up) Don't use FOREIGN_KEY_CHECKS
Bug-42068-Bug-26993-follow-up-Dont-use-FOREIGNKEYC.patch (text/plain), 2.49 KB, created by
Nick Clemens (kidclamp)
on 2026-03-11 12:45:34 UTC
(
hide
)
Description:
Bug 42068: Bug 26993 (follow-up) Don't use FOREIGN_KEY_CHECKS
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2026-03-11 12:45:34 UTC
Size:
2.49 KB
patch
obsolete
>From b2298095189b5f21a403b7e9fdf1eb4ec6009fe9 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Wed, 11 Mar 2026 12:42:49 +0000 >Subject: [PATCH] Bug 42068: Bug 26993 (follow-up) Don't use FOREIGN_KEY_CHECKS > >To test: >1 - Checkout 25.11.x - reset_all >2 - Enable StoreLastBorrower >3 - Issue an item >4 - Ensure item has a row in items_last_borrower > SELECT * FROM items_last_borrower >5 - Checkout main >6 - updatedatabase >7 - Try to delete any item, doesn't have to be the one you issued > DELETE FROM items WHERE itemnumber=93; >8 - ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`koha_kohadev`.`items_last_borrower`, CONSTRAINT `items_last_borrower_ibfk_1` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE) > >9 - repeat 1-5 >10 - APPLY PATCH >11 - updatedatabase >12 - Try to delete any item >13 - Success! >14 - Delete the item you issued previously (in the staff interface on via mysql) >15 - Confirm no rows in items_last_borrower >--- > installer/data/mysql/db_revs/251200013.pl | 20 ++++++++++++++++++-- > 1 file changed, 18 insertions(+), 2 deletions(-) > >diff --git a/installer/data/mysql/db_revs/251200013.pl b/installer/data/mysql/db_revs/251200013.pl >index 409a1a07b19..bc6d7cf9344 100755 >--- a/installer/data/mysql/db_revs/251200013.pl >+++ b/installer/data/mysql/db_revs/251200013.pl >@@ -9,7 +9,14 @@ return { > my ( $dbh, $out ) = @$args{qw(dbh out)}; > > if ( index_exists( 'items_last_borrower', 'itemnumber' ) ) { >- $dbh->do('SET FOREIGN_KEY_CHECKS=0'); >+ >+ # Drop existing foreign key >+ $dbh->do( >+ q{ >+ ALTER TABLE items_last_borrower >+ DROP FOREIGN KEY items_last_borrower_ibfk_1 >+ } >+ ); > > # Drop the unique index > $dbh->do( >@@ -17,7 +24,16 @@ return { > ALTER TABLE items_last_borrower DROP INDEX itemnumber > } > ); >- $dbh->do('SET FOREIGN_KEY_CHECKS=1'); >+ >+ # Recreate foreign key >+ $dbh->do( >+ q{ >+ ALTER TABLE items_last_borrower >+ ADD CONSTRAINT items_last_borrower_ibfk_1 >+ FOREIGN KEY (itemnumber) REFERENCES items (itemnumber) >+ ON DELETE CASCADE ON UPDATE CASCADE >+ } >+ ); > > say_success( $out, "Adjusted foreign key constraints on items_last_borrower table" ); > } >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 42068
:
195123
|
195125
|
195132
|
195136