CakePHP. How can i make a model test in a table with another primary key?

Posted by Marcelo on Stack Overflow See other posts from Stack Overflow or by Marcelo
Published on 2011-11-28T20:30:09Z Indexed on 2011/11/29 17:50 UTC
Read the original article Hit count: 294

I have this table

CREATE TABLE myexamples.problems (
  id INT,
  name VARCHAR(45) NULL ,
  pk_id INT AUTO_INCREMENT PRIMARY KEY
);

But when I try test a model in cakephp, it fails because the table has two autoincrement attributes. The following query

CREATE TABLE `test_suite_problems` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(45) DEFAULT NULL,
  `pk_id` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY  (`pk_id`)
)
DEFAULT CHARSET=latin1, COLLATE=latin1_swedish_ci, ENGINE=InnoDB;

raise this error:

"1075: Incorrect table definition; there can be only one auto column and it must be defined as a key"

I have in the model class

<?php
class Problem extends AppModel {
    var $name = 'Problem';
    var $displayField = 'name';
    var $primaryKey='problems';
}
?>

But I don't know how to make the field ID not having an autoincrement attribute, and I can't change the table structure.

© Stack Overflow or respective owner

Related posts about sql

Related posts about testing