2

While adding phinx migration, Is it possible to addColumn enum with default value? To achieve: 1. All existing rows to have the default value ('active' in this case) 2. All new entries to have the default value ('active' in this case)

Something I am building up is:

$this->table('my_table')
            ->addColumn('status', 'enum', ['values' => ['active', 'cancelled', 'expired']])
            ->create();

//how to add 'active' as default?

stack_d_code
  • 1,196
  • 2
  • 12
  • 19

1 Answers1

2

I am running Phinx 0.5.0, and the way I accomplished the default value for an ENUM type is by adding in the 'default' => '' option.

Example:

public function change()
    {
        $table = $this->table('example');
        $table->addColumn(
            'example_column',
            'enum',
            array(
                'values'  => ['abc','def','ghi'],
                'default' => 'abc'
            )
        )
            ->update();
    }

Hope this helps!

Dylan N
  • 527
  • 3
  • 13
  • Does phinx actually understand the rollback in this situation? As far as I read in the documentation it doesn't so should you be using change here? – Tom Somerville May 06 '17 at 01:26