CodeIgniter Forums
Creating an ENUM field with dbforge - 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: Creating an ENUM field with dbforge (/showthread.php?tid=9818)



Creating an ENUM field with dbforge - El Forum - 07-09-2008

[eluser]Bryan Zera[/eluser]
I'm creating an ENUM field with dbforge:

Code:
$field['enum_field'] = array(
  'type' => 'ENUM',
  'contstraint' => "'a','b','c'",
  'default'=> "a"
);
$this->dbforge->add_field($field);

Assigning the 'constraint' array key when creating database types like INT and VARCHAR put the constraint in parenthesis after the SQL type declaration, but when using ENUM as the type, it ignores the constraint. How do I set values for my ENUM fields with dbforge?


Creating an ENUM field with dbforge - El Forum - 07-10-2008

[eluser]AgentPhoenix[/eluser]
Well, it might have something to do with the fact that you misspelled constraint. Tongue


Creating an ENUM field with dbforge - El Forum - 08-28-2012

[eluser]Sean Downey[/eluser]
In case anyone else finds this the constraint should be set as

Code:
$field['enum_field'] = array(
  'type' => 'ENUM',
  'constraint' => array('a','b','c'),
  'default'=> "a"
);
$this->dbforge->add_field($field)



Creating an ENUM field with dbforge - El Forum - 07-20-2013

[eluser]goFrendiAsgard[/eluser]
[quote author="Sean Downey" date="1346167503"]In case anyone else finds this the constraint should be set as

Code:
$field['enum_field'] = array(
  'type' => 'ENUM',
  'constraint' => array('a','b','c'),
  'default'=> "a"
);
$this->dbforge->add_field($field)
[/quote]

Thank you Sean !!!
I wonder why doesn't it appeared on documentation.


Creating an ENUM field with dbforge - El Forum - 01-04-2014

[eluser]kakallatt[/eluser]
This is my code
Code:
$field['test'] = array(
  'type' => 'ENUM',
  'constraint' => array('a','b','c'),
  'default'=> "a"
);
$this->dbforge->add_field($field);
$this->dbforge->create_table('demo');

And I got a message:
Quote:Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Array) DEFAULT 'a' NOT NULL ) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci' at line 2

CREATE TABLE `ci_demo` ( `test` ENUM(Array) DEFAULT 'a' NOT NULL ) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

Please help me, thank you very much.