Codeigniter creating an ENUM field with dbforge

13.1k views Asked by At

I create a ENUM field, here is my 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:

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.

1

There are 1 answers

0
M Khalid Junaid On BEST ANSWER

Try this one

$field['test'] = array(
'type' => 'ENUM("a","b","c")',
'default' => 'a',
'null' => FALSE,
);
$this->dbforge->add_field($field);
$this->dbforge->create_table('demo'); 

Reference