Recent Topics

1 Dec 18, 2008 17:08    

I change something in a table for a plugin, and I got this error :

No KEY/INDEX defined for AUTO_INCREMENT column!

So I did it again with xdebug, and I saw that b2 was trying to do this :

in_array( $fieldname_lowered, $fields_with_keys


with $ fileds_with_keys=array('constraint')
CONSTRAINT?!?
It is because I used a create table syntax which is not supported though far more correct than the quick one :

CREATE TABLE '.$this->get_sql_table('cheval')." (
            `cheval_ID` INT(11) AUTO_INCREMENT NOT NULL ,
            `User_ID` INT(11) NOT NULL ,
            `race_ID` INT(11) default NULL ,
            genre_ID INT(11) default NULL,
            relation_ID INT(11) default NULL,
            `age` INT(2) default NULL ,
            `robe_ID` int(11) default NULL,
            `Name` VARCHAR(50) ,
            `cheval_likes` text,
            `cheval_dislikes` text,
            numdept char(3) default NULL,
            cheval_riding_school varchar(255) default NULL,
            CONSTRAINT cle_primaire PRIMARY KEY (`cheval_ID`),
            CONSTRAINT race FOREIGN KEY (race_ID) REFERENCES ".$this->get_sql_table('race')." (race_ID),
            CONSTRAINT relation FOREIGN KEY (relation_ID) REFERENCES ".$this->get_sql_table('relation')." (relation_ID),
            CONSTRAINT genre FOREIGN KEY (genre_ID) REFERENCES ".$this->get_sql_table('genre')." (genre_ID),
            CONSTRAINT robe FOREIGN KEY (robe_ID) REFERENCES ".$this->get_sql_table('robe')." (robe_ID),
            CONSTRAINT department FOREIGN KEY (numdept) REFERENCES evo_department (numdept),
            CONSTRAINT unicite UNIQUE (User_ID, Name)
            )ENGINE=InnoDB;

I defined the PRIMARY KEY on a different line, this is what caused this bug.

2 Jan 14, 2009 08:48

Let me see if I understand correctly: you hacked a plugin that doesn't work and want to know why. If this is a fair understanding then I'll say "recode it till it works". Also make sure the plugin you started from works without issue THEN make it do what you want THEN see about how "not supported though far more correct" works out.

3 Jan 14, 2009 17:45

You wnat something like

`id` int(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,


instead of

`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)


I had the same with one of my plugins. Don't ask me why but do appreciate that you are using a database abstraction layer that will check your code.

Good luck

4 Feb 04, 2009 15:14

Ooops, I did not subscribe to this topic, sorry I did not reply...
@EdB : I did not hack anything, I created my own plugin. The thing is, when you code a plugin and you change the content of the GetDbLayout() function, you can change the version number of the plugin to force your database to be like what is written in the GetDbLayout() function. This is done by a $db->delta function, which compares the database with the function. The problem is it detects a column CONSTRAINT and tries to create it when I use the "far more correct" syntax.
@afwas : I'm glad this database abstraction layer exists, but I'd like it to support more kinds of syntax, that's all. By the way, what if you want to add a unique constraint on two fields if you can't just add this kind of line:

CONSTRAINT UNIQUE(field1, field2)


Thanks for you replies


Form is loading...