Koha Check-In Not Working? Here’s a Temporary Fix for Auto Increment Problems
Library administrators using Koha may sometimes encounter a strange issue — books just don’t check in. No matter how many times you try, the transaction hangs. The culprit? Auto increment errors in the underlying MySQL or MariaDB database.
This guide offers a practical, field-tested solution that can temporarily resolve the issue and get your circulation back on track.
The Problem: Broken Auto Increment in Koha Tables
When Koha fails to assign new unique IDs in tables like issues
, borrowers
, or items
, it leads to check-in and circulation errors. These database inconsistencies often stem from deleted records that disrupt the sequence of auto-incremented fields.
Affected tables usually include:
old_issues
deleteditems
deletedbiblio
deletedborrowers
Step 1: Access Your Database
Open a terminal and connect to your MySQL/MariaDB server:
sudo mysql -uroot -p
Switch to your Koha database:
USE koha_library;
Step 2: Manually Delete Problem Entries
Identify and remove problematic records using the following SQL commands:
DELETE FROM old_issues WHERE issue_id IN (1001, 1002);
DELETE FROM deletedbiblio WHERE biblionumber IN (201, 202);
DELETE FROM deleteditems WHERE biblionumber IN (301, 302);
DELETE FROM deletedborrowers WHERE borrowernumber IN (401, 402);
Modify the IDs according to the actual invalid entries found in your system.
Exit MySQL:
sqlCopyEditexit;
Step 3: Set Up Auto Increment Fix Script
Next, update the DB config file depending on your OS:
- Ubuntu 16.04 (MySQL):
/etc/mysql/my.cnf
- Ubuntu 18.04 (MySQL):
/etc/mysql/mysql.conf.d/mysqld.cnf
- Debian 9 or Ubuntu 16.04 (MariaDB):
/etc/mysql/mariadb.conf.d/50-server.cnf
Under the [mysqld]
section, add:
init-file=/var/lib/mysql/init-file_koha_library.sql
Step 4: Create Initialization SQL File
Now create the initialization file:
sudo leafpad /var/lib/mysql/init-file_koha_library.sql
Paste this code (adjust DB name if needed):
USE koha_library;
SET @id1 = (SELECT GREATEST(IFNULL(MAX(borrowernumber),0), IFNULL((SELECT MAX(borrowernumber) FROM deletedborrowers),0)) + 1);
SET @sql = CONCAT('ALTER TABLE borrowers AUTO_INCREMENT = ', @id1);
PREPARE stmt FROM @sql; EXECUTE stmt;
-- Repeat the logic for other tables like biblio, items, issues, and reserves
Save and close the file.
Step 5: Restart Database Service
Apply your changes:
sudo service mysql restart
Wrap-Up
This workaround resolves check-in problems caused by ID mismatches in Koha’s backend. It’s not a permanent fix, but it restores functionality while developers work on a full patch. Always ensure you back up your database before applying changes.
Credit By
Omkar Kakeru
Founder Of PlayTech