cakephp / phinx

PHP Database Migrations for Everyone
https://phinx.org
MIT License
4.45k stars 895 forks source link

Unable to use `Literal` as column type #2254

Closed zeleznypa closed 7 months ago

zeleznypa commented 7 months ago

The MysqlAdapter.php failed on this line when the \Phinx\Util\Literal is used as the column type.

$table = $this->table('import');
$table->addColumn('is_active', Literal::from('boolean'));
$import->save();

https://github.com/cakephp/phinx/blob/5b423937a86f2d84d67429c8bae39e672d0fee3b/src/Phinx/Db/Adapter/PdoAdapter.php#L666

TypeError: Phinx\Db\Adapter\PdoAdapter::getDefaultValueDefinition(): Argument #2 ($columnType) must be of type ?string, Phinx\Util\Literal given, called in /opt/srv/project/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/MysqlAdapter.php on line 1391 and defined in /opt/srv/project/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php:666
Stack trace:
#0 /opt/srv/project/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/MysqlAdapter.php(1391): Phinx\Db\Adapter\PdoAdapter->getDefaultValueDefinition(NULL, Object(Phinx\Util\Literal))
#1 /opt/srv/project/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/MysqlAdapter.php(332): Phinx\Db\Adapter\MysqlAdapter->getColumnSqlDefinition(Object(Phinx\Db\Table\Column))
#2 /opt/srv/project/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/AdapterWrapper.php(354): Phinx\Db\Adapter\MysqlAdapter->createTable(Object(Phinx\Db\Table\Table), Array, Array)
#3 /opt/srv/project/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/TimedOutputAdapter.php(114): Phinx\Db\Adapter\AdapterWrapper->createTable(Object(Phinx\Db\Table\Table), Array, Array)
#4 /opt/srv/project/vendor/robmorgan/phinx/src/Phinx/Db/Plan/Plan.php(147): Phinx\Db\Adapter\TimedOutputAdapter->createTable(Object(Phinx\Db\Table\Table), Array, Array)
#5 /opt/srv/project/vendor/robmorgan/phinx/src/Phinx/Db/Table.php(722): Phinx\Db\Plan\Plan->execute(Object(Phinx\Db\Adapter\TimedOutputAdapter))
#6 /opt/srv/project/vendor/robmorgan/phinx/src/Phinx/Db/Table.php(618): Phinx\Db\Table->executeActions(false)
#7 /opt/srv/project/vendor/robmorgan/phinx/src/Phinx/Db/Table.php(691): Phinx\Db\Table->create()
#8 /opt/srv/project/database/Migrations/20240112000000_test.php(52): Phinx\Db\Table->save()
#9 /opt/srv/project/vendor/robmorgan/phinx/src/Phinx/Migration/Manager/Environment.php(112): Test->up()
#10 /opt/srv/project/vendor/robmorgan/phinx/src/Phinx/Migration/Manager.php(389): Phinx\Migration\Manager\Environment->executeMigration(Object(Test), 'up', false)
#11 /opt/srv/project/vendor/robmorgan/phinx/src/Phinx/Migration/Manager.php(360): Phinx\Migration\Manager->executeMigration('default', Object(Test), 'up', false)
#12 /opt/srv/project/vendor/robmorgan/phinx/src/Phinx/Console/Command/Migrate.php(124): Phinx\Migration\Manager->migrate('default', 20240112000000, false)
#13 /opt/srv/project/vendor/symfony/console/Command/Command.php(326): Phinx\Console\Command\Migrate->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /opt/srv/project/vendor/symfony/console/Application.php(1063): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /opt/srv/project/vendor/symfony/console/Application.php(320): Symfony\Component\Console\Application->doRunCommand(Object(Phinx\Console\Command\Migrate), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /opt/srv/project/vendor/symfony/console/Application.php(174): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /opt/srv/project/bin/console.php(15): Symfony\Component\Console\Application->run()
#18 /opt/srv/project/bin/console(6): require('/opt/srv/project...')
#19 {main}