Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP 3 migration missing enum

I have a question;

Has anyone experienced to migrate a table using CakePHP 3 Migration Tool that when a specific field is an ENUM data type, the migration script automatically converts it into string or text.

How can I avoid it and how can I maintain the data type from ENUM?

Thanks

like image 272
bowmeow Avatar asked Sep 17 '25 21:09

bowmeow


1 Answers

It depends on the driver in use, since enum is not supported by all database systems. For the MySQL driver, using the enum type will result in the appropriate DDL.

Migration class:

public function up()
{
    $table = $this->table('testenum');
    $table
        ->addColumn('enum_column', 'enum', [
            'values' => ['one', 'two']
        ])
        ->create();
}

DDL:

CREATE TABLE `testenum` (
  `enum_column` enum('one','two') NOT NULL,
  PRIMARY KEY (`id`)
) 

In the Phinx package, enum is present only in the MysqlAdapter.

like image 177
code-kobold Avatar answered Sep 23 '25 12:09

code-kobold