cakephp / phinx

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

Argument #2 ($columnType) must be of type ?string, Phinx\Util\Literal given #2230

Closed kolorafa closed 7 months ago

kolorafa commented 11 months ago

There is a types miss-match between

https://github.com/cakephp/phinx/blob/26753bdb66827383781eb0033b34cb467da1d12c/src/Phinx/Db/Adapter/PdoAdapter.php#L630

and

https://github.com/cakephp/phinx/blob/26753bdb66827383781eb0033b34cb467da1d12c/src/Phinx/Db/Table/Column.php#L213 https://github.com/cakephp/phinx/blob/26753bdb66827383781eb0033b34cb467da1d12c/src/Phinx/Db/Adapter/MysqlAdapter.php#L1391

Failing with:

TypeError: Phinx\Db\Adapter\PdoAdapter::getDefaultValueDefinition(): Argument #2 ($columnType) must be of type ?string, Phinx\Util\Literal given, called in /app/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/MysqlAdapter.php on line 1391 and defined in /app/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php:630
Stack trace:
#0 /app/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/MysqlAdapter.php(1391): Phinx\Db\Adapter\PdoAdapter->getDefaultValueDefinition(NULL, Object(Phinx\Util\Literal))
#1 /app/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/MysqlAdapter.php(332): Phinx\Db\Adapter\MysqlAdapter->getColumnSqlDefinition(Object(Phinx\Db\Table\Column))
#2 /app/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/AdapterWrapper.php(350): Phinx\Db\Adapter\MysqlAdapter->createTable(Object(Phinx\Db\Table\Table), Array, Array)
#3 /app/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/TimedOutputAdapter.php(114): Phinx\Db\Adapter\AdapterWrapper->createTable(Object(Phinx\Db\Table\Table), Array, Array)

I'm trying to create add Generated column.

->addColumn(
     'event',
    Literal::from('tinyint(1) GENERATED ALWAYS AS (`stringField` IS NOT NULL) STORED NOT NULL ')
)

Unless there is some new way to define generated fields?

Thanks