@@ -, +, @@ index/foreign key to items --- .../mysql/atomicupdate/Bug-18705-collections_tracking-fk-items.sql | 3 +++ installer/data/mysql/kohastructure.sql | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 installer/data/mysql/atomicupdate/Bug-18705-collections_tracking-fk-items.sql --- a/installer/data/mysql/atomicupdate/Bug-18705-collections_tracking-fk-items.sql +++ a/installer/data/mysql/atomicupdate/Bug-18705-collections_tracking-fk-items.sql @@ -0,0 +1,3 @@ +DELETE FROM collections_tracking WHERE itemnumber NOT IN (SELECT itemnumber FROM items WHERE items.itemnumber = collections_tracking.itemnumber); +ALTER TABLE collections_tracking ADD CONSTRAINT FOREIGN KEY `coltra-fk-items` (itemnumber) REFERENCES items (itemnumber); + --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -448,7 +448,9 @@ CREATE TABLE collections_tracking ( transferred tinyint(1) DEFAULT '0', date_added datetime DEFAULT NULL, timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (collections_tracking_id) + PRIMARY KEY (collections_tracking_id), + CONSTRAINT `coltra-fk-items` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) + ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- --