如何通过cakephp phinx迁移迁移列键入双重迁移



我正在尝试使用phinx迁移将表从db1到db2迁移,但是我对一个表列有列类型DOUBLE的表有问题。我知道受支持的类型是否存在Phinx列类型,但是可以指定FLOAT类型以在DIFF_MIGRATION中获取DOUBLE吗?我使用cakephp版本3.5.6。

我的示例migration_diff

<?php
   use MigrationsAbstractMigration;
   class Diff003 extends AbstractMigration
{
public function up()
{
    $this->table('test_double')
        ->addColumn('double1', 'float', [ // here type DOUBLE is changing to  FLOAT
            'default' => null,
            'limit' => null,
            'null' => true,
        ])
        ->addColumn('double2', 'float', [
            'default' => null,
            'limit' => null,
            'null' => true,
        ])
        ->create();
}
public function down()
{
    $this->dropTable('test_double');
}

}

DOUBLE类型最近已实现,可能会在下一个phinx版本中使用(截至版本为0.10.7),请参见> https://github.com/cakephp/phinx/pull/1493

在此之前,您可以使用自定义列类型功能

->addColumn('double1', PhinxUtilLiteral::from('DOUBLE'), [
    // ...
])

或通过RAW SQL手动添加列,类似于:

$this->execute('ALTER TABLE test_double ADD COLUMN double1 DOUBLE NULL');

,或者如果您冒险,请使用Phinx Master分支,直到可用稳定版本为止:

composer require robmorgan/phinx:dev-master
->addColumn('double1', 'double', [
    // ...
])

最新更新