Skip to content

Custom data types (data domain) not working (mysql) #1810

Closed
@kristapsk

Description

@kristapsk

Tried to create custom data types as per documentation, but they aren't working.

phinx.yml:

paths:
    migrations: '%%PHINX_CONFIG_DIR%%/db/migrations'
    seeds: '%%PHINX_CONFIG_DIR%%/db/seeds'

environments:
    default_migration_table: phinxlog
    default_environment: development
    production:
        adapter: mysql
        host: localhost
        name: production_db
        user: root
        pass: ''
        port: 3306
        charset: utf8

    development:
        adapter: mysql
        host: localhost
        name: phinx_test
        user: phinx_test
        pass: 'phinx_test'
        port: 3306
        charset: utf8

    testing:
        adapter: mysql
        host: localhost
        name: testing_db
        user: root
        pass: ''
        port: 3306
        charset: utf8

version_order: creation

data_domain:
    test_type:
        type: string
        length: 666

Test migration script:

<?php

use Phinx\Migration\AbstractMigration;

class TestMigration extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    addCustomColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Any other destructive changes will result in an error when trying to
     * rollback the migration.
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $this->table('test')
            ->addColumn('test_column', 'test_type')
            ->create();
    }
}

When trying migration, got error:

$ ./vendor/bin/phinx migrate
Phinx by CakePHP - https://phinx.org.

using config file ./phinx.yml
using config parser yml
using migration paths 
 - /home/user/test/phinx/db/migrations
using seed paths 
warning no environment specified, defaulting to: development
using adapter mysql
using database phinx_test
ordering by creation time

 == 20200617223037 TestMigration: migrating
InvalidArgumentException: An invalid column type "test_type" was specified for column "test_column". in /home/user/test/phinx/vendor/robmorgan/phinx/src/Phinx/Db/Table.php:305
Stack trace:
#0 /home/user/test/phinx/db/migrations/20200617223037_test_migration.php(35): Phinx\Db\Table->addColumn()
#1 /home/user/test/phinx/vendor/robmorgan/phinx/src/Phinx/Migration/Manager/Environment.php(109): TestMigration->change()
#2 /home/user/test/phinx/vendor/robmorgan/phinx/src/Phinx/Migration/Manager.php(377): Phinx\Migration\Manager\Environment->executeMigration()
#3 /home/user/test/phinx/vendor/robmorgan/phinx/src/Phinx/Migration/Manager.php(350): Phinx\Migration\Manager->executeMigration()
#4 /home/user/test/phinx/vendor/robmorgan/phinx/src/Phinx/Console/Command/Migrate.php(123): Phinx\Migration\Manager->migrate()
#5 /home/user/test/phinx/vendor/symfony/console/Command/Command.php(258): Phinx\Console\Command\Migrate->execute()
#6 /home/user/test/phinx/vendor/symfony/console/Application.php(911): Symfony\Component\Console\Command\Command->run()
#7 /home/user/test/phinx/vendor/symfony/console/Application.php(264): Symfony\Component\Console\Application->doRunCommand()
#8 /home/user/test/phinx/vendor/robmorgan/phinx/src/Phinx/Console/PhinxApplication.php(69): Symfony\Component\Console\Application->doRun()
#9 /home/user/test/phinx/vendor/symfony/console/Application.php(140): Phinx\Console\PhinxApplication->doRun()
#10 /home/user/test/phinx/vendor/robmorgan/phinx/bin/phinx(28): Symfony\Component\Console\Application->run()
#11 {main}

Using phinx 0.12.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions