exist rule syntax


I have a table=> USERS where the EMAIL column is unique.

How can i sepcify a rule to ensure that this constraint is not violated ?

I tried using this , but, it returns me a mysql unique key constraint exception

array(‘email’,‘exist’,‘className’=>‘Users’, ‘attributeName’ => ‘EMAIL’),



You have either to

catch the exception when the same email is inserted in the table,

or create a validator to check if the mail already exist in the db

have a look here: http://www.yiiframework.com/doc/api/1.0.10/CValidator

there is a CUniqueValidator