About rules and mysql

Hello,

There is something I am not yet sure about in yii2, if you set an email as "unique" in MYSQL but do not set it as unique in the rules inside the model, what will happen.

Will Yii2 check to see if mysql has set that field to unique? But if it is set to Unique in the app and not unique in mysql, will it let the email be recorded still int he database?

When I am lost is on why we have to set in the app the rules + set the same rules in mysql.

Thanks for your help,

Ben

Exception will happen since Yii will try to write to DB and DB won’t allow it.

Got it, thank you so much SamDark:-)