MySQL INSERT:列'描述'不能为空,但没有列名称' description'

时间:2017-09-21 13:44:37

标签: mysql

我试图在MySQL表上执行INSERT语句。 表结构如下

CREATE TABLE `charges` (
  `sgl_id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL,
  `opportunity_id` int(11) NOT NULL,
  `invoice_id` int(11) NOT NULL,
  `product_id` int(11) NOT NULL,
  `comment` text NOT NULL,
  `quantity` float(18,2) NOT NULL,
  `rate` float(18,2) NOT NULL,
  `subtotal` float(18,2) NOT NULL,
  `tax` float(18,2) NOT NULL,
  `total` float(18,2) NOT NULL,
  `override_rate` tinyint(1) NOT NULL,
  `charge_datetime` datetime NOT NULL,
  `created_on` datetime NOT NULL,
  `modified_on` datetime NOT NULL,
  `created_by` int(11) NOT NULL,
  `status_id` int(11) NOT NULL,
  `sub_status_id` int(11) NOT NULL,
  `status_date` date NOT NULL,
  `status_user_id` int(11) NOT NULL,
  `status_comment` text NOT NULL,
  `mf_id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `payment_id` int(11) NOT NULL,
  `auto_charge` tinyint(1) NOT NULL,
  `store_id` int(11) NOT NULL,
  `booking_id` int(11) NOT NULL,
  `reversal_charge_id` int(11) NOT NULL,
  `revenue_reported` tinyint(1) NOT NULL,
  `package_product_id` int(11) NOT NULL,
  PRIMARY KEY (`sgl_id`),
  KEY `sgl_id_idx` (`sgl_id`),
  KEY `customer_id_idx` (`account_id`),
  KEY `opportunity_id_idx` (`opportunity_id`),
  KEY `invoice_id_idx` (`invoice_id`),
  KEY `product_id_idx` (`product_id`),
  KEY `status_id_idx` (`status_id`),
  KEY `quantity_idx` (`quantity`),
  KEY `rate_idx` (`rate`),
  KEY `tax_idx` (`tax`),
  KEY `total_idx` (`total`),
  KEY `sub_status_id_idx` (`sub_status_id`),
  KEY `mf_id_idx` (`mf_id`),
  KEY `override_rate_idx` (`override_rate`),
  KEY `created_by_idx` (`created_by`),
  KEY `charge_datetime` (`charge_datetime`),
  KEY `created_on` (`created_on`,`modified_on`,`status_date`),
  KEY `subtotal_idx` (`subtotal`),
  KEY `company_id_idx` (`company_id`),
  KEY `payment_id_idx` (`payment_id`),
  KEY `auto_charge_idx` (`auto_charge`),
  KEY `store_id_idx` (`store_id`),
  KEY `booking_id_idx` (`booking_id`),
  KEY `reversal_charge_id_idx` (`reversal_charge_id`),
  KEY `revenue_reported_idx` (`revenue_reported`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT语句

INSERT INTO charges (created_on, created_by, status_id, status_date, status_user_id, sub_status_id, account_id, product_id, comment, quantity, rate, subtotal, tax, total, override_rate, charge_datetime, modified_on, company_id, package_product_id) VALUES ('2017-09-21 09:06:27', '510', '7', '2017-09-21', '510', '59', '817350', '2331', 'Adjustment Charge', '-1', '5.00', '-5', '0', '-5', '1', '2017-09-21 09:06:27', '2017-09-21 09:06:28', '51', '0')

我得到的错误是

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'description' cannot be null

没有名为' description'在表中,但仍然,MySQL正在抛出一个错误,即'描述'不能为空。

我没有足够的触发器知识,但有一个INSERT触发器。

CREATE TRIGGER `charges_insert_trigger` AFTER INSERT ON `charges`
 FOR EACH ROW BEGIN
        DECLARE change_flag,header_id,sgl_trigger_flag int;
        DECLARE description, var_name varchar(500);
        SET description = "";
        SET change_flag = 0;
        SET var_name = "";
        SET sgl_trigger_flag = (SELECT count(*) FROM system_prefs WHERE prefname='sgl_trigger_flag' AND prefvalue = '1');
        IF sgl_trigger_flag <> 0
        THEN
        IF (SELECT @sgl_user_id IS NULL)
        THEN
            SET @sgl_user_id = 0;
            SET @sgl_user_name = "System User";
        END IF;        SET var_name = (SELECT name FROM products where sgl_id = NEW.product_id);
        SET description = CONCAT("Charge (ID: ",NEW.sgl_id,") for ", var_name," is added");
        IF NEW.opportunity_id > 0
        THEN

          INSERT INTO changes_log_headers(`user_id`, `user_name`, `changelog_table_name`, `type`, `created_on`, `record_id`, `description`,`account_id`) VALUES (@sgl_user_id,@sgl_user_name,'opportunities','update', NOW(), NEW.opportunity_id, description, NEW.account_id);  
        ELSE
          INSERT INTO changes_log_headers(`user_id`, `user_name`, `changelog_table_name`, `type`, `created_on`, `record_id`, `description`, `account_id`, `show_in_accounts`) VALUES (@sgl_user_id,@sgl_user_name,'accounts','update', NOW(), NEW.account_id, description, NEW.account_id, 1);  
        END IF;        END IF;
        END

1 个答案:

答案 0 :(得分:0)

您的表格可能与另一个列名为&#34; ERR: unsupported sum iterator type: *influxql.booleanInterruptIterator&#34;不能为NULL。

你应该填写那个字段