0

我大约 98% 确定这个查询在 mysql 5.1 上运行正常。我们已经将我们的一台机器升级到了 mysql 5.6,我正在运行更新,并且它通过这个查询得到一个数据库错误:

 UPDATE diagnostic 
    LEFT JOIN contact ON diagnosticdata_suppliercontact = contact_id
    SET diagnosticdata_suppliercontact = NULL
    WHERE (!contactdata_issupplier) OR (contact.contact_id IS NULL);

但是,表模式允许它为 NULL。有谁知道 mysql 5.6 中发生的任何可能导致我们悲伤的问题或变化?

以下是对该表的说明:

mysql> describe diagnostic;
+--------------------------------+-------------+------+-----+---------+----------------+
| Field                          | Type        | Null | Key | Default | Extra          |
+--------------------------------+-------------+------+-----+---------+----------------+
| diagnostic_id                  | int(11)     | NO   | PRI | NULL    | auto_increment |
| diagnostic_time                | int(15)     | NO   |     | NULL    |                |
| diagnostic_user                | int(15)     | NO   |     | NULL    |                |
| diagnosticdata_time            | int(15)     | NO   |     | NULL    |                |
| diagnosticdata_user            | int(15)     | NO   |     | NULL    |                |
| diagnosticdata_name            | varchar(50) | NO   |     | NULL    |                |
| diagnosticdata_suppliercontact | int(11)     | YES  | MUL | NULL    |                |
+--------------------------------+-------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)

ERROR 1048 (23000): Column 'diagnosticdata_suppliercontact' cannot be null

CREATE STATEMENT IS HERE TO 有触发器:

delimiter $$

CREATE TABLE `diagnostic` (
  `diagnostic_id` int(11) NOT NULL AUTO_INCREMENT,
  `diagnostic_time` int(15) NOT NULL,
  `diagnostic_user` int(15) NOT NULL,
  `diagnosticdata_time` int(15) NOT NULL,
  `diagnosticdata_user` int(15) NOT NULL,
  `diagnosticdata_name` varchar(50) NOT NULL,
  `diagnosticdata_suppliercontact` int(11) DEFAULT NULL,
  PRIMARY KEY (`diagnostic_id`),
  KEY `diagnostic_suppliercontact` (`diagnosticdata_suppliercontact`) USING BTREE,
  CONSTRAINT `fk_diagnosticdata_suppliercontact_contact` FOREIGN KEY (`diagnosticdata_suppliercontact`) REFERENCES `contact` (`contact_id`)
) ENGINE=InnoDB AUTO_INCREMENT=188 DEFAULT CHARSET=utf8$$

CREATE
DEFINER=`dotuser`@`localhost`
TRIGGER `ezymerged`.`diagnostic_insert`
AFTER INSERT ON `ezymerged`.`diagnostic`
FOR EACH ROW
BEGIN
    REPLACE INTO  ezymerged_history.diagnostic 
     SELECT diagnostic.* FROM ezymerged.diagnostic 
      WHERE diagnostic_id=NEW.diagnostic_id;                    
END
$$

CREATE
DEFINER=`dotuser`@`localhost`
TRIGGER `ezymerged`.`diagnostic_update`
AFTER UPDATE ON `ezymerged`.`diagnostic`
FOR EACH ROW
BEGIN
    REPLACE INTO  ezymerged_history.diagnostic 
     SELECT diagnostic.* FROM ezymerged.diagnostic 
      WHERE diagnostic_id=NEW.diagnostic_id;                    
END
$$
4

1 回答 1

0

虽然diagnosticdata_suppliercontact允许NULLs 约束:

CONSTRAINT `fk_diagnosticdata_suppliercontact_contact`
FOREIGN KEY (`diagnosticdata_suppliercontact`)
REFERENCES `contact` (`contact_id`)

将优先,并要求 in的值在表中的字段中diagnosticdata_suppliercontact具有匹配的值。contact_idcontact

于 2013-05-07T00:32:04.383 回答