Welcome Guest, Not a member yet? Register   Sign In
dbforge - can only be one auto column and it must be defined as a key
#1

Hi guys,

Just wondering if you could assist with an error I'm seeing.

The code:
PHP Code:
$this->dbforge->add_field('post_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT');
        
$this->dbforge->add_field('title VARCHAR(255) NOT NULL');
        
$this->dbforge->add_field('slug VARCHAR(255) NOT NULL');
        
$this->dbforge->add_field('body TEXT NULL');
        
$this->dbforge->add_field('created_on DATETIME NOT NULL');
        
$this->dbforge->add_field('modified_on DATETIME NULL');
        
$this->dbforge->add_field('deleted TINYINT(1) NOT NULL DEFAULT 0');
        
$this->dbforge->add_key('post_id'TRUE);
        
        
$this->dbforge->create_table('posts'); 

The error:

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

CREATE TABLE `bf_posts` ( id INT(20) UNSIGNED NOT NULL AUTO_INCREMENT, title VARCHAR(255) NOT NULL, slug VARCHAR(255) NOT NULL, body TEXT NULL, created_on DATETIME NOT NULL, modified_on DATETIME NULL, deleted TINYINT(1) NOT NULL DEFAULT 0 ) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_general_ci

It looks to be like the primary key element isn't being added to the query. Do you have any suggestions?

Thanks!
Reply
#2

(This post was last modified: 10-31-2015, 09:06 PM by orionstar.)

Try to use an array as a parameter with the add_field method.

And check the userguide:
http://www.codeigniter.com/user_guide/da...ing-fields

Quote:Passing raw strings as fields cannot be followed by add_key() calls on those fields.
Reply
#3

(10-31-2015, 08:56 PM)orionstar Wrote: Try to use an array as a parameter with the add_field method.

And check the userguide:
http://www.codeigniter.com/user_guide/da...ing-fields


Quote:Passing raw strings as fields cannot be followed by add_key() calls on those fields.

Bah, I read the userguide but missed that large Note box haha.

Did try passing an array before I posted the thread but it gave the same result. Turns out the document wasn't uploading when I was saving it... your suggestion worked now that I have the ftp working again.

Cheers! 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB