PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, March 17, 2022

[FIXED] How to migrate column type DOUBLE via cakephp phinx migrations?

 March 17, 2022     cakephp, migration, mysql, phinx     No comments   

Issue

I'm trying to migrate table from db1 to db2 with using 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, but it is possible to specify FLOAT type to get DOUBLE in diff_migration ? I use cakephp version 3.5.6.

My example 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');
}

}


Solution

The DOUBLE type has been implemented recently, and will probably be available in the next Phinx release (it's been added as of version 0.10.7), see https://github.com/cakephp/phinx/pull/1493.

Until then you can for example use the custom column type feature:

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

or manually add the columns via raw SQL, something like:

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

or if you're adventurous, use the Phinx master branch until the stable release is available:

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


Answered By - ndm
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing