![]() |
can't create primary key using dbforge add_key() - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: can't create primary key using dbforge add_key() (/showthread.php?tid=17037) |
can't create primary key using dbforge add_key() - El Forum - 03-24-2009 [eluser]Unknown[/eluser] I want create table with multiple primary keys. Example, I want create this table using dbforge: CREATE TABLE `test` ( `id_user` int(11) NOT NULL default '0', `id_record` int(11) NOT NULL default '0', `id_option` int(11) NOT NULL default '0', `description` varchar(128) NOT NULL default '', PRIMARY KEY (`id_user`,`id_record`,`id_option`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; $fields = array( 'id_user' => array('type' => 'INT', 'default' => '0', 'constraint' => '11'), 'id_record' => array('type' => 'INT', 'default' => '0', 'constraint' => '11'), 'id_option' => array('type' => 'INT', 'default' => '0','constraint' => '11'), 'description' => array('type' => 'VARCHAR', 'default' => '', 'constraint' => '128') ); $this->dbforge->add_field($fields); $this->dbforge->add_key('id_user', true); $this->dbforge->add_key('id_record', true); $this->dbforge->add_key('id_option', true); $this->dbforge->create_table('test', true); error at primary key creation. How it is possible to create such primary key using db_forge? can't create primary key using dbforge add_key() - El Forum - 03-24-2009 [eluser]jedd[/eluser] Welcome to the forums. I haven't used DBforge, but just guessing here. Quote:I want create table with multiple primary keys. Btw, a subtle distinction, but you actually want to create a table with a composite or compound (I never remember which) primary key. A table can have just one PK, by definition. EDIT: my bad - never even looked at CI's dbforge stuff before, and grossly misread the original question. Readingthe CI manual now, there's this hint: Code: $this->dbforge->add_key('blog_id', TRUE); Which suggests something particularly odd, unless it's a typo. The only reference to multiple keys, explicitly refers to non-primary multiple keys. Oddness. What if you try add_key('id_1 , id_2 , id_3') ? (I really prefer making my own .mysql text files for feeding into the database - so little pain.) can't create primary key using dbforge add_key() - El Forum - 03-24-2009 [eluser]Unknown[/eluser] I want created one primary key on a some columuns... My code generate the next sql-query: CREATE TABLE IF NOT EXISTS `test` ( `id_user` INT(11) DEFAULT '0', `id_record` INT(11) DEFAULT '0', `id_option` INT(11) DEFAULT '0', `description` VARCHAR(128) DEFAULT '', PRIMARY KEY `id_user_id_record_id_option` () ) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; if I'am replase: $this->dbforge->add_key(‘id_user’, true); $this->dbforge->add_key(‘id_record’, true); $this->dbforge->add_key(‘id_option’, true); on: $this->dbforge->add_key('id_user , id_record , id_option', true); then generate CREATE TABLE IF NOT EXISTS `test` ( `id_user` INT(11) DEFAULT '0', `id_record` INT(11) DEFAULT '0', `id_option` INT(11) DEFAULT '0', `description` VARCHAR(128) DEFAULT '', PRIMARY KEY `id_user` , id_record , id_option () ) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; |