Error creating table with DBForge using enum |
I'm trying to figure out the proper format to use when defining ENUM fields in CI 3.
Under CI 2, I have the following field definition: PHP Code: private $permissions_new_fields = array( Then the migration looks something like this: PHP Code: $this->dbforge->add_field($this->permissions_new_fields); All of which worked fine (and I just dumped my test database and re-ran the migration to make sure it still works) under CI 2. Under CI 3, using the MySQLi driver, the same migration file gives me the following: Quote:A Database Error Occurred Although the error says "Invalid default value for 'status'", the issue seems to be that the constraint on the 'status' field has been defined incorrectly: Code: `status` ENUM('\'active\',\'inactive\',\'deleted\'') NOT NULL DEFAULT 'active' I've tried several variations, including an array and defining the constraint as 'active,inactive,deleted', but each variation I've tried so far has given me a slightly different incorrect result. The output I'm expecting would look something like this: Code: `status` ENUM('active','inactive','deleted') NOT NULL DEFAULT 'active'
Have you tried using a string instead of an array for the field definition? I know it should work with array like it did in v2, but maybe as a temp workaround...
http://www.codeigniter.com/user_guide/da...-as-fields
Generally, I avoid using the string format unless absolutely necessary, which, so far, has only been the case for setting things like 'CURRENT_TIMESTAMP'. In this case, my work-around is to move the 'constraint' into the 'type' field, like this:
PHP Code: 'status' => array( Since ENUM is a MySQL-specific type anyway, it's not the worst work-around, but it would be nice if I could use the constraint. (04-20-2015, 06:20 AM)mwhitney Wrote: Generally, I avoid using the string format unless absolutely necessary, which, so far, has only been the case for setting things like 'CURRENT_TIMESTAMP'. In this case, my work-around is to move the 'constraint' into the 'type' field, like this: Was looking for a work around for this as well, and came to the same conclusion you did. PHP Code: $db_columns = array( And its the same thing for SET |
Welcome Guest, Not a member yet? Register Sign In |