Welcome Guest, Not a member yet? Register   Sign In
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.


Messages In This Thread
DBForge Updating ENUM Values/Constraints - by El Forum - 09-04-2013, 02:18 PM



Theme © iAndrew 2016 - Forum software by © MyBB