Im getting problems when trying to set columns (particularly foreign key ones) as null instead of blank in my database.
I have two tables being
Booking and Archive.
When a booking is complete or deleted it is placed in the archive table.
The problem is there are a few fields which may be empty including two foreign key fields.
If there value is empty I need null to be placed in there field.
Currently the system attempts to add blank space into the fields which causes a foreign key contraint error show below.
Runing Booking Function test 123 fake streed Invalid query: Cannot add or update a child row: a foreign key constraint fails (`taxi booking system`.`archive`, CONSTRAINT `archive_ibfk_9` FOREIGN KEY (`Driver_ID`) REFERENCES `drivers` (`ID`)) Whole query: INSERT INTO Archive (ID, From_Address, From_Lat, From_Lng, To_Address, To_Lat, To_Lng, Driver_ID, Customer_ID, Date, Status, Reason, Created, Special_Request, Complete) VALUES ('8', '123 Fakestreet', '50.822563', '-1.071819', '', '', '', '', '', '0000-00-00 00:00:00', '1', '', '2012-01-11 14:50:03', '', '1');DriverID and CustomerID are both forigen keys in the table however in this case they are blank and causing the error.
I have tried checking each variable and if its empty placing "NULL" into it, however the database seems to still accept that as a string and gives the same error
Can anyone tell me how to correctly add NULL to any fields which are empty?
Thanks in advance
Ben Gibson
Help
















