MySQL Trigger doesn't know default values
I am using this trigger
delimiter ||
create TRIGGER column_a_to_default
BEFORE INSERT ON `property`
FOR EACH ROW
BEGIN
IF NEW.primary_image = '' THEN
SET NEW.primary_image = default(NEW.primary_image);
END IF;
END;
||
delimiter ;
If I insert into a table, the trigger throws an error:
The 'primary_image' field has no default.
But it is so!
What's wrong here? The trigger doesn't seem to know the default values!
EDIT
Create script table
CREATE TABLE IF NOT EXISTS `property` (
`id` varchar(10) NOT NULL,
`images` text NOT NULL,
`primary_image` varchar(100) NOT NULL DEFAULT '../no-image.png',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+3
source to share
2 answers