Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter creating an ENUM field with dbforge

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.

like image 782
Joshua Hansen Avatar asked Jan 05 '14 06:01

Joshua Hansen


1 Answers

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

like image 86
M Khalid Junaid Avatar answered Nov 07 '22 15:11

M Khalid Junaid