Skip to content
Advertisement

MySQL trigger not functioning correctly

I currently working my AWS RDS MySQL through R notebook.

I have a table like this:

With a trigger like this

I could create table and trigger without problems; however, when I insert something like this

The insertion was successful but I would get an instance of fruit with ‘C’, instead of ‘A’

Wonder if anyone has some insights, thank!

Advertisement

Answer

The ENUM is being checked even before the trigger is fired. So because the value you’re trying to insert doesn’t exist in the enum, the insert is failing.

You can fix this by removing the enum and replacing it with a varchar. You might be able to manage this with a CHECK constraint, but you need to be on MySQL 8.0.16 or greater.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement