doctrine / migrations

Doctrine Database Migrations Library
https://www.doctrine-project.org/projects/migrations.html
MIT License
4.65k stars 387 forks source link

Column 'TABLE_NAME' in where clause is ambiguous #1395

Closed dsentker closed 5 months ago

dsentker commented 5 months ago

Bug Report

Q A
BC Break yes/no
Version 3.5.5

Summary

After upgrading doctrine/migrations from 3.3.2 to 3.5.5 (along with a Symfony Update from 5.3 to 5.4) i experienced an error when running any doctrine:migrations:* command: "Integrity constraint violation: 1052 Column 'TABLE_NAME' in where clause is ambiguous "

Current behavior

$ php bin/console doctrine:migrations:current -vv

In ExceptionConverter.php line 72:

  [Doctrine\DBAL\Exception\NonUniqueFieldNameException (1052)]                                                                                           
  An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'TABLE_NAME' in where clause is ambiguous  

Exception trace:
  at /var/www/html/vendor/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php:72
 Doctrine\DBAL\Driver\API\MySQL\ExceptionConverter->convert() at /var/www/html/vendor/doctrine/dbal/src/Connection.php:1938
 Doctrine\DBAL\Connection->handleDriverException() at /var/www/html/vendor/doctrine/dbal/src/Connection.php:1880
 Doctrine\DBAL\Connection->convertExceptionDuringQuery() at /var/www/html/vendor/doctrine/dbal/src/Connection.php:1105
 Doctrine\DBAL\Connection->executeQuery() at /var/www/html/vendor/doctrine/dbal/src/Schema/MySQLSchemaManager.php:478
 Doctrine\DBAL\Schema\MySQLSchemaManager->selectTableColumns() at /var/www/html/vendor/doctrine/dbal/src/Schema/AbstractSchemaManager.php:255
 Doctrine\DBAL\Schema\AbstractSchemaManager->doListTableColumns() at /var/www/html/vendor/doctrine/dbal/src/Schema/MySQLSchemaManager.php:91
 Doctrine\DBAL\Schema\MySQLSchemaManager->listTableColumns() at /var/www/html/vendor/doctrine/dbal/src/Schema/AbstractSchemaManager.php:485
 Doctrine\DBAL\Schema\AbstractSchemaManager->doListTableDetails() at /var/www/html/vendor/doctrine/dbal/src/Schema/MySQLSchemaManager.php:83
 Doctrine\DBAL\Schema\MySQLSchemaManager->listTableDetails() at /var/www/html/vendor/doctrine/dbal/src/Schema/AbstractSchemaManager.php:614
 Doctrine\DBAL\Schema\AbstractSchemaManager->introspectTable() at /var/www/html/vendor/doctrine/migrations/lib/Doctrine/Migrations/Metadata/Storage/TableMetadataStorage.php:209
 Doctrine\Migrations\Metadata\Storage\TableMetadataStorage->needsUpdate() at /var/www/html/vendor/doctrine/migrations/lib/Doctrine/Migrations/Metadata/Storage/TableMetadataStorage.php:236
 Doctrine\Migrations\Metadata\Storage\TableMetadataStorage->checkInitialization() at /var/www/html/vendor/doctrine/migrations/lib/Doctrine/Migrations/Metadata/Storage/TableMetadataStorage.php:82
 Doctrine\Migrations\Metadata\Storage\TableMetadataStorage->getExecutedMigrations() at /var/www/html/vendor/doctrine/migrations/lib/Doctrine/Migrations/Version/DefaultAliasResolver.php:63
 Doctrine\Migrations\Version\DefaultAliasResolver->resolveVersionAlias() at /var/www/html/vendor/doctrine/migrations/lib/Doctrine/Migrations/Tools/Console/Command/CurrentCommand.php:34
 Doctrine\Migrations\Tools\Console\Command\CurrentCommand->execute() at /var/www/html/vendor/symfony/console/Command/Command.php:298
 Symfony\Component\Console\Command\Command->run() at /var/www/html/vendor/symfony/console/Application.php:1058
 Symfony\Component\Console\Application->doRunCommand() at /var/www/html/vendor/symfony/framework-bundle/Console/Application.php:96
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /var/www/html/vendor/symfony/console/Application.php:301
 Symfony\Component\Console\Application->doRun() at /var/www/html/vendor/symfony/framework-bundle/Console/Application.php:82
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/html/vendor/symfony/console/Application.php:171
 Symfony\Component\Console\Application->run() at /var/www/html/bin/console:43

At first i thought my migration files are corrupted or invalid, but that is not the case: Even when i remove all migrations, the error comes up. It seems that the error is thrown before the migration itself is read/executed.

This is also supported by the fact that the error occurs with every migrate command. It seems like there is an error reading the migration information.

The database connection is definitely correct - with doctrine:query I can execute queries via doctrine (e.g. doctrine:query:sql) without any problems.

How to reproduce

It is hard to say what exactly is required to reproduce this.

Expected behavior

I can run all doctrine:migrations:* commands without errors.


Edit: The TABLE_NAME value appears exactly in the error message, it was not changed/redacted by me.

dsentker commented 5 months ago

I found out The error has its origins in doctrine/dbal. I created an issue there.