I'm trying to set a NULL
value in the deserved_slope_2
column when the user edits the value in a form. Unfortunately this column is a foreign key that links to a primary key (auto increment index) of a column of another table.
When running the request I get:
Error Number: 1452
Cannot add or update a child row: a foreign key constraint fails (`game_skisimulation`.`game_created_lifts`, CONSTRAINT `fk_game_created_lifts_game_created_slopes2` FOREIGN KEY (`deserved_slope_2`) REFERENCES `game_created_slopes` (`id_created_slopes`) ON DE)
UPDATE game_created_lifts SET deserved_slope_2 = '0' WHERE id_created_lifts = '200' LIMIT 1
I've read that this is because the NULL ID doesn't exist in the referred table. Unfortunately it seems that I cannot set NULL either in this column:
A primary key column cannot contain NULL values.
How can I solve this problem?
I want to set NULL in the deserved_slope_2
column (to reset it).
-- Table structure for table game_created_lifts
CREATE TABLE `game_created_lifts` (
`id_created_lifts` int(11) NOT NULL,
`id_player` int(11) NOT NULL,
`deserved_slope_1` int(11) DEFAULT NULL,
`deserved_slope_2` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- RELATIONS FOR TABLE `game_created_lifts`:
-- `deserved_slope_1`
-- `game_created_slopes` -> `id_created_slopes`
-- `deserved_slope_2`
-- `game_created_slopes` -> `id_created_slopes`
-- Table structure for table game_created_slopes
CREATE TABLE `game_created_slopes` (
`id_created_slopes` int(11) NOT NULL,
`id_player` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;