• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DBForge Updating ENUM Values/Constraints

#1
[eluser]Unknown[/eluser]
Hey guys,
I'm using CodeIgniter's migrations functionality on an app I'm building, and I've ran into a very frustrating issue with trying to update enum fields values.

According to what I've read, creating an ENUM field requires setting the constraint in an array like below:

Code:
$field['enum_field'] = array(
‘type’ => ’ENUM’,
‘constraint’ => array(‘a’,'b’,'c’), // Note this is an array here
‘default’=> ”a”
);
$this->dbforge->add_field($field)

However if you try to modify the ENUM column constraint using an array like that, it will throw a php error about an array to string conversion.

So an FYI to anyone, if you are trying to update the constraint value for an ENUM field in CodeIgniter's DBForge, it has to be a string as per below.
Code:
# Change the ENUM contstraint for EmployeeRole to include a contractor role
$field = array(
    'EmployeeRole' => array(
        'type' => "ENUM",
        'constraint' => "'Employee','Admin','Contractor'",
        'default' => 'Employee'
    )
);
        
# Modify the field
$this->dbforge->modify_column('Employees', $field);

Hopefully this saves someone a little banging their head on the desk time.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.