Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
DBUtils add_field bug
  • Hi,

    When trying to add a field of data type bit via a migration script with a default I receive an error similar to following:
    "incorrect default for field"

    This is because Fuel decided to put the default value in quotes, so you end up with something similar to (from memory):
    ALTER TABLE 'table_name' ADD field BIT DEFAULT '1' 

    This statement fails due to the quotes around the default value.

    I have tried the following to no avail:
    \DBUtil::add_fields('users', array(
        'surname' => array('constraint' => 1, 'type' => 'bit', 'default' => 1)
    ));
    \DBUtil::add_fields('users', array(
        'surname' => array('constraint' => 1, 'type' => 'bit', 'default' => (int) 1)
    ));

    Any thought or ideas? or is this actually a bug?
  • HarroHarro
    Accepted Answer
    Can you create an issue for this at https://github.com/fuel/core/issues?

    You can work around it using

    \DBUtil::add_fields('users', array(
        'surname' => array('constraint' => 1, 'type' => 'bit', 'default' => \DB::expr(1))
    ));

    which will prevent escaping the value.
  • thanks for the work around - i simply ran an sql statement after field add to default it. yours is more elegant though. issue created 
  • Thanks. Someone will look into it soon.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion