1
Reference issue:
I have the following SQL:
CREATE TABLE IF NOT EXISTS `setores` (
`set_cod` int(10) NOT NULL AUTO_INCREMENT,
`set_base` int(10) NOT NULL,
`set_setor` varchar(50) NOT NULL,
`set_data` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`set_status` enum('0','1') NOT NULL DEFAULT '0',
PRIMARY KEY (`set_cod`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
ALTER TABLE `setores`
ADD CONSTRAINT `relaciona_pai` FOREIGN KEY (`set_base`)
REFERENCES `setores` (`set_cod`)
ON DELETE CASCADE ON UPDATE CASCADE;
However, when I add a new record, set_base comes NULL.
SQL de Insert:
`INSERT INTO setores(set_cod, set_base, set_setor, set_data, set_status) VALUES (1,1,"raiz",1,1);`
How can I resolve the issue?
INSERT INTO setores( set_base, set_setor, set_status) VALUES (1,"raiz",1);
you entered so? because set_cod is auto increment and set_data is Current_timestamp so you don’t need to insert.– Angélica Flausino
Yeah, I put it like this
– Sr. André Baill