8

I'm trying to create a migration in Phinx (actually a rollback) which will create a enum type field in a MySQL DB. Having read the docs I was under the impression that this should be pretty simple but it just fails every time.

$table = $this->table('mytable');
$table->addColumn('warmth','enum', array('limit' => array('1', '2', '3', '4', '5', 'P', 'A', 'B', 'C', 'D', 'X', 'N')))
->save();

Unfortunately there's no easy way to have Phinx output the offending SQL query either.

Nathan Pitman
  • 2,286
  • 4
  • 30
  • 46

2 Answers2

25

Use latest version from master (above 0.5.x-dev):

$this->table('my_table')
->addColumn('status', 'enum', ['values' => ['enabled', 'disabled']])
->save();
hshhhhh.name
  • 366
  • 3
  • 4
2

Maybe for others it will be interesting that there is another way to add an ENUM column

use Phinx\Db\Adapter\MysqlAdapter;
use Phinx\Db\Table\Column;

$this->table('posts')
    ->addColumn(
        (new Column())
            ->setName('status')
            ->setType(MysqlAdapter::PHINX_TYPE_ENUM)
            ->setValues([
                'draft', 'publish', 'private', 'trash',
            ])
    )
    ->update();