Make sure column length is a nullable integer #7048
Closed
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
I got the following exception when running migrations in a symfony project:
In Column.php line 115: [TypeError] Doctrine\DBAL\Schema\Column::setLength(): Argument #1 ($length) must be of type ?int, string given, called in /app/vendor/doctrine/dbal/src/Schema/Column.php on line 102 Exception trace: at /app/vendor/doctrine/dbal/src/Schema/Column.php:115 Doctrine\DBAL\Schema\Column->setLength() at /app/vendor/doctrine/dbal/src/Schema/Column.php:102 Doctrine\DBAL\Schema\Column->setOptions() at /app/vendor/doctrine/dbal/src/Schema/Column.php:84 Doctrine\DBAL\Schema\Column->__construct() at /app/vendor/doctrine/dbal/src/Schema/MySQLSchemaManager.php:212 Doctrine\DBAL\Schema\MySQLSchemaManager->_getPortableTableColumnDefinition() at /app/vendor/doctrine/dbal/src/Schema/AbstractSchemaManager.php:815 Doctrine\DBAL\Schema\AbstractSchemaManager->_getPortableTableColumnList() at /app/vendor/doctrine/dbal/src/Schema/AbstractSchemaManager.php:128 Doctrine\DBAL\Schema\AbstractSchemaManager->listTableColumns() at /app/vendor/doctrine/dbal/src/Schema/AbstractSchemaManager.php:460 Doctrine\DBAL\Schema\AbstractSchemaManager->introspectTable() at /app/vendor/doctrine/migrations/src/Metadata/Storage/TableMetadataStorage.php:199 Doctrine\Migrations\Metadata\Storage\TableMetadataStorage->needsUpdate() at /app/vendor/doctrine/migrations/src/Metadata/Storage/TableMetadataStorage.php:181 Doctrine\Migrations\Metadata\Storage\TableMetadataStorage->ensureInitialized() at /app/vendor/doctrine/migrations/src/Tools/Console/Command/MigrateCommand.php:158 Doctrine\Migrations\Tools\Console\Command\MigrateCommand->execute() at /app/vendor/symfony/console/Command/Command.php:318 Symfony\Component\Console\Command\Command->run() at /app/vendor/symfony/console/Application.php:1092 Symfony\Component\Console\Application->doRunCommand() at /app/vendor/symfony/framework-bundle/Console/Application.php:123 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /app/vendor/symfony/console/Application.php:341 Symfony\Component\Console\Application->doRun() at /app/vendor/symfony/framework-bundle/Console/Application.php:77 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /app/vendor/symfony/console/Application.php:192 Symfony\Component\Console\Application->run() at /app/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:49 Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run() at /app/vendor/autoload_runtime.php:29 require_once() at /app/bin/console:16I ended up tracking it down to the following problem. When
PDO::ATTR_STRINGIFY_FETCHESis set to true on the mysql connection, all results are cast to string.In the code for getting the correct collumn length we see the following, where
$tableColumnis the result of a query.Since the
setLenghtmethod expects?int, we get a type error because we pass a string.