Welcome Guest, Not a member yet? Register   Sign In
Creating an ENUM field with dbforge
#1

[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?
#2

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

[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)
#4

[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.
#5

[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.




Theme © iAndrew 2016 - Forum software by © MyBB