如何通过 cakephp phinx 迁移迁移列类型 DOUBLE?

How to migrate column type DOUBLE via cakephp phinx migrations?

我正在尝试使用 Phinx migrations, but i have a problem with one table where i have column type DOUBLE. I know that supported types are there Phinx column type 将 table 从 db1 迁移到 db2,但可以指定 FLOAT 类型以在 [= 中获取 DOUBLE 21=] ?我用的是cakephp版本3.5.6.

我的例子migration_diff

<?php
   use Migrations\AbstractMigration;

   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 .

在那之前你可以使用 custom column type feature:

->addColumn('double1', \Phinx\Util\Literal::from('DOUBLE'), [
    // ...
])

或通过原始 SQL 手动添加列,例如:

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

或者如果您喜欢冒险,请使用 Phinx master 分支直到稳定版本可用:

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