I hope you have already solved your problem. If not, I may have some questions to clarify:
1.- What do you mean with
A new row is added in both tables at the same time[...]
Is it that you use one call to the DB in which you insert both rows? Because I guess you are doing two queries on one call. One that inserts into vtiger_assets and then one that inserts into vtiger_assetscf
If it is the case, maybe you are triggering the ativos
trigger before you have the row from wich to copy the data.
2.- With
with a new assetid automatically added
I supose you have your auto_increment
property enabled for the assetid column, but this makes me wonder, why do you have separate tables if one just copy data recently sent?
Maybe you could send one query only to vtiger_assets and have a trigger in that table (not into vtiger_assetscf) that creates a new row into vtiger_assetscf (but now I think maybe your tables are not completely shown here....)
3.- Finally: Is your assetid
a key column? (if you're using auto_increment, I bet it is). If it's the case, I think the error you get is that you try to insert a row in a table with a duplicate value (the assetid
).
Maybe try this instead:
create trigger `ativos` after insert on `vtiger_assetscf`
for each row
begin
update `vtiger_assets` SET `assetname` = new.`cf_658` WHERE `assetid` = NEW.`assetid`;
end#
I know It's been a while, but still...