How to add integrity constraint check on all controllers while inserting values to db in YII? what is the simplest method for it?

if($model->save())
                $this->redirect(array('view','id'=>$model->id));

Exception appear here

CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '9-5' for key 'xyz'. The SQL statement executed was: INSERT INTO `tbl_table` (`xyz`, `x`, `x`, `x`, `x`, `x`, `x`, `created`) VALUES (:yp0, :yp1, :yp2, :yp3, :yp4, :yp5, :yp6, NOW())
有帮助吗?

解决方案

CMysqlSchema is the class for retrieving metadata information from a MySQL database and COciSchema is the class for retrieving metadata information from an Oracle database.u can make use of the methods provided by these classes to check for the constraints for example u can make use of the method findConstraints()

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top