I have a table 'weekrit' that has a primary key, that consists of a 'startdatum' (date value that is the first day of the week) and a 'ritid' (a number starting with 1 every week) I use a BEFORE INSERT trigger In the webside database to autoincrement the 'ritid' value. On the website it works fine.
I made an export of the database and imported that in my localhost database. In this developer-environment the trigger does not seem to work: every insert in this table fails:
Errorno: 1364 Errormessage: "Field 'ritid' doesn't have a default value"
This is the INSERT statement:
INSERT INTO weekrit(startdatum, chauffeur, datum, tijdstip, combiheen, klantnaam, ritcode, van, bestemming, tijdretour, combiretour, ritprijs, betaalwijze, fooi, betaalwijzefooi, eigenrolstoel, opmerkingen, aangemaakt_door, telefoon_contact, contactnaam, tijdstempel) VALUES ("2025-06-09", "GR", "2025-06-09", "10:00:00", "N", "Jan Test", "", "Van Adres", "Bestemmingsadres", "11:00:00", "N", 28.00, "", "", "", "N", "", "", "", "", "")
This is the trigger:
CREATE TRIGGER `trgIncrementWeekrit` BEFORE INSERT ON `weekrit` FOR EACH ROW SET NEW.ritid = (
SELECT IFNULL(MAX(ritid), 0) + 1
FROM weekrit
WHERE startdatum = NEW.startdatum
)
I tried to do an export of the 'weekrit' table (including the trigger) from the website database alone and I imported that again locally, but that made no difference. Again everything works fine on the website, but I cannot get it working in the developer environment. Any suggestions?
SELECT VERSION();in the website database and the development database. Are they the same?show triggers like 'weekrit';SET NEW.ritid =coalesce((SELECT ... WHERE startdatum = NEW.startdatum),1).