Re: MySQL error on field update
Thanks everyone! It turned out that the db field wasn't set to auto-increment. I thought it was, but must have forgotten to tick the box and not noticed! Once I changed that, it worked fine. Thanks again for the help. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
Re: MySQL error on field update
There can't be a primary key ID of 0 as 0 = false. As such you're not passing an id to saveField so it's running an INSERT instead of an UPDATE. You need to take a look at your db table definition as it should not allow a primary key of 0 if it's an INT/Primary Key/Auto Increment which it should be. HTH Paul Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
RE: MySQL error on field update
I've seen something like this before, for some odd reason instead of erroring before it submits the sql, it will try and use an array as the value, and the first value of that array is an "L". Do a pr before the saveField command and see what could possibly have a string that starts with L Also try running your save like this $this->PdfPref->save(array('landscape'=> $this->data['PdfPref'] ['landscape'])); -Original Message- From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf Of WhyNotSmile Sent: Monday, March 22, 2010 4:51 AM To: CakePHP Subject: MySQL error on field update I'm trying to update a record in the database, but I keep getting an error saying SQL Error: 1062: Duplicate entry '0' for key 'PRIMARY' Query: INSERT INTO `pdf_prefs` (`landscape`) VALUES ('L') Here's what I'm doing: $this->PdfPref->id = $id;/* $id = 0 in this case */ $this->PdfPref->saveField('landscape', $this->data['PdfPref'] ['landscape']); I've tried various other ways and nothing has worked. I have similar things working in other models, but this one just won't work for me at all! Can anyone suggest what I'm doing wrong? Thanks! Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
Re: MySQL error on field update
Like the msg says, it looks like you already have a row in the DB with ID = 0. As it's the Primary Key, it must be unique. But you should never have any records that have the PKs set to 0, anyway. How did you specify this column when you created the table? It should be some flavour of INT and be AUTO_INCREMENT. On Mar 22, 7:50 am, WhyNotSmile wrote: > I'm trying to update a record in the database, but I keep getting an > error saying > > SQL Error: 1062: Duplicate entry '0' for key 'PRIMARY' > Query: INSERT INTO `pdf_prefs` (`landscape`) VALUES ('L') > > Here's what I'm doing: > > $this->PdfPref->id = $id; /* $id = 0 in this case */ > $this->PdfPref->saveField('landscape', $this->data['PdfPref'] > ['landscape']); > > I've tried various other ways and nothing has worked. I have similar > things working in other models, but this one just won't work for me at > all! > > Can anyone suggest what I'm doing wrong? > > Thanks! Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
MySQL error on field update
I'm trying to update a record in the database, but I keep getting an error saying SQL Error: 1062: Duplicate entry '0' for key 'PRIMARY' Query: INSERT INTO `pdf_prefs` (`landscape`) VALUES ('L') Here's what I'm doing: $this->PdfPref->id = $id;/* $id = 0 in this case */ $this->PdfPref->saveField('landscape', $this->data['PdfPref'] ['landscape']); I've tried various other ways and nothing has worked. I have similar things working in other models, but this one just won't work for me at all! Can anyone suggest what I'm doing wrong? Thanks! Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.