title: Duplicate Entry error for Unique key on Update Yii Framework
body: <p>I am facing the following error while trying to update the record in my table:</p>
  
  <pre><code>CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'ABCD1111P' for key 'pan_UNIQUE'
  </code></pre>
  
  <p>Table has column i.e. "pan" which has unique key assigned.</p>
  
  <p>And following is my code in controller:</p>
  
  <pre><code>$model-&gt;pan = $_POST['CustomerBasics']['pan'];
  $model-&gt;cell = $_POST['CustomerBasics']['cell'];
  $model-&gt;gender = $_POST['PersonalDetails']['gender'];
  
  $valid = $model-&gt;validate();
              print_r($model-&gt;getErrors());
              if ($valid) {
                  $model-&gt;update();
                  $personal_details_id = $model-&gt;personal_details_id;
              }
  </code></pre>
  
  <p>And in Model:</p>
  
  <pre><code>array('pan', 'unique', 'on' =&gt; 'insert', 'message' =&gt; '{attribute}:{value} already exists!'),
  </code></pre>
  
  <p>What is the issue? Where I am going wrong?</p>
  
  <p>Thanks.</p>