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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With