how do i update a primary key

how do i update the primary key…i used find method and then updated in the normal way and called save() method…but it is nothing working…so someone help me

I never updated a primary key before in my life.

I wonder what kind of situation needs this.  :o

In this case, you should consider using updateByPk() method.

I understood update THE PK and not BY PK.  ???

Check the signature of this method and you will understand. You will need to provide the old PK as the first parameter and the new PK in the second parameter array.

yeah thanks i got it

I have a table with 2 PK (name,userid) and I want to update only the first.

If I use:




There’s an error

The value for the column "userid" is not supplied when querying the table "mytable".

If I use:


array('name'=>$this->oldName, 'userid'=>1),


It works but only for the records with userid=1

How can I update only the values of the first PK no matter what the value of the second is?

It works in every other way except for updateByPk, since you don’t specify all primary columns. Use updateAll for instance.