mysql的列不能为null触发器

时间:2013-08-12 18:17:13

标签: mysql stored-procedures triggers

我遇到类似here所述的错误。即使我使用insert命令传递了值,我也会收到NULL字段错误。这是我的表,触发器和过程的sql导出:

--TRIGGER
CREATE TRIGGER `ubaci_nagradu`
AFTER INSERT ON `Dokumenti`
FOR EACH ROW CALL generiraj_nagradu(NEW.k_fk)


--INSERT COMMAND
INSERT INTO `Dokumenti` (`d_putanja`, `d_naziv`, `d_opis`, `k_fk`, `d_mime`, `d_ime`) VALUES ('/home/path/uploads/', 'TTTT', 'TTTTTTTTTTTTT', '1', 'application/pdf', 'diplomski-prezantacija1376329220.pdf')

--PROCEDURE
CREATE DEFINER=`studentx`@`localhost` PROCEDURE `generiraj_nagradu`(IN `korisnik_id` INT UNSIGNED)
BEGIN  
    DECLARE ID INT(11);
    DECLARE OPIS VARCHAR(45);
    DECLARE BROJ INT(11);
    SELECT n_id INTO @ID FROM Nagrade;
    SELECT n_opis INTO @OPIS FROM Nagrade;
    SELECT n_broj INTO @BROJ FROM Nagrade;
    IF (@BROJ > 0) THEN
        INSERT INTO KorisnikNagrada VALUES (NULL, korisnik_id, @ID, NOW());
        INSERT INTO Notifikacije VALUES (NULL, @korisnik_id, "Dobili ste nagradu: " + @OPIS, 0);
        SET BROJ = BROJ - 1;
        UPDATE Nagrade SET n_broj = @BROJ WHERE n_id = @ID;
    END IF;
END

--TABLES
CREATE TABLE IF NOT EXISTS `Dokumenti` (
    `d_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `d_naziv` varchar(250) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
    `d_opis` tinytext CHARACTER SET utf8 COLLATE utf8_unicode_ci,      
    `d_putanja` varchar(250) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,      
    `k_fk` int(10) unsigned NOT NULL,
    `d_mime` varchar(50) DEFAULT NULL,      
    `d_ime` varchar(250) NOT NULL,      
    PRIMARY KEY (`d_id`),
    KEY `dokumenti_korisnici_idx` (`k_fk`)
) 
ENGINE=InnoDB  
DEFAULT CHARSET=latin1 AUTO_INCREMENT=19;

CREATE TABLE IF NOT EXISTS `KorisnikNagrada` (
  `kn_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `k_fk` int(10) unsigned NOT NULL,
  `n_fk` int(10) unsigned NOT NULL,
  `kn_vrijeme` datetime NOT NULL,
  PRIMARY KEY (`kn_id`),
  KEY `k_fk` (`k_fk`),
  KEY `n_fk` (`n_fk`),
  KEY `k_fk_2` (`k_fk`),
  KEY `n_fk_2` (`n_fk`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ;

CREATE TABLE IF NOT EXISTS `Notifikacije` (
  `nt_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `k_fk` int(10) unsigned NOT NULL,
  `nt_poruka` tinytext CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `nt_vidjeo` tinyint(1) NOT NULL,
  PRIMARY KEY (`nt_id`),
  KEY `k_fk` (`k_fk`),
  KEY `k_fk_2` (`k_fk`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

感谢任何帮助:-) 最好的祝福, 丹尼尔

0 个答案:

没有答案