I am using MySQL Workbench to create a database. I have a table called USERS defined as follows:
delimiter $$
CREATE TABLE `users` (
`UID` int(10) unsigned NOT NULL AUTO_INCREMENT
`USERNAME` varchar(20) NOT NULL,
`PASSWORD` varchar(64) NOT NULL
PRIMARY KEY (`UID`),
UNIQUE KEY `USER_NAME_UNIQUE` (`USERNAME`),
KEY `USERS_ROLES_REF_IDX` (`USER_ROLE`),
CONSTRAINT `USERS_ROLES_REF` FOREIGN KEY (`USER_ROLE`) REFERENCES `roles_ref` (`ROLE_NAME`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8$$
CREATE
DEFINER=`root`@`localhost`
TRIGGER `MyDB`.`users_after_ins_trig`
AFTER INSERT ON `MyDB`.`users`
FOR EACH ROW
begin
insert into profiles (username) VALUES (new.username);
end
$$
When I go to forward engineer the database and create it, the script gives me the following error. As you can see from above, the username is part of the table. What gives?
Executing SQL script in server
ERROR: Error 1054: Unknown column 'username' in 'field list'
INSERT INTO `MyDB`.`USERS` (`UID`, `USERNAME`, `PASSWORD`)
VALUES (NULL, 'user1', 'blahpassword')
解决方案
Could it be that you are inserting into profiles from your trigger? I'm guessing profiles does not have a username column.