Yii Framework Forum: Integrity Constraint Violation: 1062 Duplicate Entry - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Integrity Constraint Violation: 1062 Duplicate Entry Error when save in Yii Rate Topic: -----

#1 User is offline   Mr.H 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 09-April 13

Posted 22 April 2013 - 05:03 AM

Hi,
I have problem when save model: Integrity constraint violation: 1062 Duplicate entry. But I checked in database the value for this column not have.
This problem happend when deleted one record and immediatly create new record with the old value for unique column.

I think this problem happend by cache but not sure and how to fix it?

Please help!!!
0

#2 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,600
  • Joined: 04-March 10
  • Location:UK

Posted 22 April 2013 - 05:08 AM

Can you show the code you're using? Are you wrapping the calls in a transaction?

EDIT: Also, which is the unique column and what does it represent?
0

#3 User is offline   codesutra 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 596
  • Joined: 15-March 11
  • Location:India

Posted 22 April 2013 - 07:24 AM

View PostMr.H, on 22 April 2013 - 05:03 AM, said:

Hi,
I have problem when save model: Integrity constraint violation: 1062 Duplicate entry. But I checked in database the value for this column not have.
This problem happend when deleted one record and immediatly create new record with the old value for unique column.

I think this problem happend by cache but not sure and how to fix it?

Please help!!!



i guess your are saving record within a loop.So, if this is a case then you should use

$this->isNewRecord=true;
//and after 
$this->save();
//use 
$this->primaryKey=null;

CodeSutra
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users