mysql - “字段列表”中的未知列“created_by”-触发器
问题描述
我正在尝试创建触发器但收到错误消息。非常感谢您提供的任何指导。仅供参考-我是初学者....
CREATE DEFINER=root@localhost TRIGGER txn-trg
before INSERT ON transactions
FOR EACH row
if (created_by = (select id from users where role_id=2),type_id=1, internal_status_id=2 , status='STL')
then set new.status='FINANCE';
elseif (status<>'STL',internal_status_id<>2,type_id<>1)
then set new.status='status';
end if;
当我将记录保存在事务表中时,它返回错误消息为
SQL 错误 [1054] [42S22]: (conn=253) Unknown column
created_by
in 'field list' 。字段 created_by 是存在于事务表中的有效字段。
上一篇MySQL Trigger Check if Row Field Exists没有回答上述查询。
事务表 DDL
CREATE TABLE transactions (
id bigint(20) NOT NULL AUTO_INCREMENT,
internal_status_id bigint(20) NOT NULL,
type_id bigint(20) NOT NULL,
created_by bigint(20) NOT NULL,
PRIMARY KEY (id),
KEY transactions_int_status_FK (internal_status_id),
KEY transactions_type_fk (type_id),
KEY transactions_assigned_created_by_fk (created_by),
CONSTRAINT transactions_assigned_created_by_fk FOREIGN KEY (created_by) REFERENCES users (id),
CONSTRAINT transactions_type_FK FOREIGN KEY (type_id) REFERENCES transaction_types (id)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=latin1;
用户表 DDL
CREATE TABLE users (
id bigint(20) NOT NULL AUTO_INCREMENT,
role_id bigint(20) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY user_user_name_un (user_name),
KEY users_fk (role_id),
CONSTRAINT user_role_fk FOREIGN KEY (role_id) REFERENCES roles (id)
) ENGINE=InnoDB AUTO_INCREMENT=142 DEFAULT CHARSET=latin1;
解决方案
推荐阅读
- javascript - 使用testcafé,如何同时登录多个服务?
- ubuntu - 按下退格键时命令行跳转到上一行
- user-interface - 根据 IBM 碳设计系统,应用程序标题栏的尺寸应该是多少?
- c# - 单元测试 - 检查空
- javascript - 如何将 TypeScript 类型添加到 Bootstrap 多级下拉列表的 jQuery 代码片段?
- php - 无法上传图片;拉拉维尔 6.0
- javascript - React Redux 没有返回预期状态
- r - 具有特定模式的栅格图层上的采样点
- java - 如何使用 C# 作为目标语言在 Antlr 中修复“当前上下文中不存在字符/_input”?
- vue.js - 从源“http://localhost:3000”访问“https://***”处的 XMLHttpRequest 已被 CORS 策略阻止