DDC-214: schema-tool --complete-update throw PDOException on DROP INDEX #267

Closed
opened 2026-01-22 12:32:45 +01:00 by admin · 21 comments
Owner

Originally created by @doctrinebot on GitHub (Dec 16, 2009).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user rickdt:

Here is the stack trace

SchemaTool: exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1025 Error on rename of './fna*common/#sql-665_60b' to './fna_common/fna_owned*insurance' (errno: 150)' in /home/eric/Zend/workspaces/DefaultWorkspace7/fna/lib/Doctrine/DBAL/Connection.php:571
Stack trace:
#0 /home/eric/Zend/workspaces/DefaultWorkspace7/fna/lib/Doctrine/DBAL/Connection.php(571): PDO->query('DROP INDEX fna_...')
#1 /home/eric/Zend/workspaces/DefaultWorkspace7/fna/lib/Doctrine/ORM/Tools/SchemaTool.php(537): Doctrine\DBAL\Connection->execute('DROP INDEX fna_...')
#2 /home/eric/Zend/workspaces/DefaultWorkspace7/fna/lib/Doctrine/ORM/Tools/Cli/Tasks/SchemaToolTask.php(217): Doctrine\ORM\Tools\SchemaTool->updateSchema(Array, false)
#3 /home/eric/Zend/workspaces/DefaultWorkspace7/fna/lib/Doctrine/ORM/Tools/Cli/CliController.php(190): Doctrine\ORM\Tools\Cli\Tasks\SchemaToolTask->run()
#4 /home/eric/Zend/workspaces/DefaultWorkspace7/fna/application/scripts/doctrine/doctrine.php(19): Doctrine\ORM\Tools\Cli\CliController->run(Array)
#5 /home/eric/Zend/workspaces/DefaultWorkspace7/fna/application/scripts/doctrine/doctrine(4): include('/home/eric/Zend...')
#6 {main}

#0 /home/eric/Zend/workspaces/DefaultWorkspace7/fna/lib/Doctrine/ORM/Tools/Cli/CliController.php(190): Doctrine\ORM\Tools\Cli\Tasks\SchemaToolTask->run()
#1 /home/eric/Zend/workspaces/DefaultWorkspace7/fna/application/scripts/doctrine/doctrine.php(19): Doctrine\ORM\Tools\Cli\CliController->run(Array)
#2 /home/eric/Zend/workspaces/DefaultWorkspace7/fna/application/scripts/doctrine/doctrine(4): include('/home/eric/Zend...')
#3 {main}

I think the problem is in the Schema Comparator. It generate a DROP for a foreign key index.

If you compare the index definition from database and from metadata you will see that the foreign key index is present only in the definition obtained from database.

Database :

Array
(
    [primary] => Doctrine\DBAL\Schema\Index Object
        (
            [_columns:protected] => Array
                (
                    [0] => id
                )

            [_isUnique:protected] => 1
            [_isPrimary:protected] => 1
            [_name:protected] => PRIMARY
        )

    [fna*client*id] => Doctrine\DBAL\Schema\Index Object
        (
            [_columns:protected] => Array
                (
                    [0] => fna*client*id
                )

            [_isUnique:protected] =>
            [_isPrimary:protected] =>
            [*name:protected] => fna_client*id
        )

)

From metadata :

Array
(
    [primary] => Doctrine\DBAL\Schema\Index Object
        (
            [_columns:protected] => Array
                (
                    [0] => id
                )

            [_isUnique:protected] => 1
            [_isPrimary:protected] => 1
            [_name:protected] => primary
        )

)
Originally created by @doctrinebot on GitHub (Dec 16, 2009). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user rickdt: Here is the stack trace ``` SchemaTool: exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1025 Error on rename of './fna*common/#sql-665_60b' to './fna_common/fna_owned*insurance' (errno: 150)' in /home/eric/Zend/workspaces/DefaultWorkspace7/fna/lib/Doctrine/DBAL/Connection.php:571 Stack trace: #0 /home/eric/Zend/workspaces/DefaultWorkspace7/fna/lib/Doctrine/DBAL/Connection.php(571): PDO->query('DROP INDEX fna_...') #1 /home/eric/Zend/workspaces/DefaultWorkspace7/fna/lib/Doctrine/ORM/Tools/SchemaTool.php(537): Doctrine\DBAL\Connection->execute('DROP INDEX fna_...') #2 /home/eric/Zend/workspaces/DefaultWorkspace7/fna/lib/Doctrine/ORM/Tools/Cli/Tasks/SchemaToolTask.php(217): Doctrine\ORM\Tools\SchemaTool->updateSchema(Array, false) #3 /home/eric/Zend/workspaces/DefaultWorkspace7/fna/lib/Doctrine/ORM/Tools/Cli/CliController.php(190): Doctrine\ORM\Tools\Cli\Tasks\SchemaToolTask->run() #4 /home/eric/Zend/workspaces/DefaultWorkspace7/fna/application/scripts/doctrine/doctrine.php(19): Doctrine\ORM\Tools\Cli\CliController->run(Array) #5 /home/eric/Zend/workspaces/DefaultWorkspace7/fna/application/scripts/doctrine/doctrine(4): include('/home/eric/Zend...') #6 {main} #0 /home/eric/Zend/workspaces/DefaultWorkspace7/fna/lib/Doctrine/ORM/Tools/Cli/CliController.php(190): Doctrine\ORM\Tools\Cli\Tasks\SchemaToolTask->run() #1 /home/eric/Zend/workspaces/DefaultWorkspace7/fna/application/scripts/doctrine/doctrine.php(19): Doctrine\ORM\Tools\Cli\CliController->run(Array) #2 /home/eric/Zend/workspaces/DefaultWorkspace7/fna/application/scripts/doctrine/doctrine(4): include('/home/eric/Zend...') #3 {main} ``` I think the problem is in the Schema Comparator. It generate a DROP for a foreign key index. If you compare the index definition from database and from metadata you will see that the foreign key index is present only in the definition obtained from database. Database : ``` Array ( [primary] => Doctrine\DBAL\Schema\Index Object ( [_columns:protected] => Array ( [0] => id ) [_isUnique:protected] => 1 [_isPrimary:protected] => 1 [_name:protected] => PRIMARY ) [fna*client*id] => Doctrine\DBAL\Schema\Index Object ( [_columns:protected] => Array ( [0] => fna*client*id ) [_isUnique:protected] => [_isPrimary:protected] => [*name:protected] => fna_client*id ) ) ``` From metadata : ``` Array ( [primary] => Doctrine\DBAL\Schema\Index Object ( [_columns:protected] => Array ( [0] => id ) [_isUnique:protected] => 1 [_isPrimary:protected] => 1 [_name:protected] => primary ) ) ```
admin added the Bug label 2026-01-22 12:32:45 +01:00
admin closed this issue 2026-01-22 12:32:46 +01:00
Author
Owner

@doctrinebot commented on GitHub (Dec 16, 2009):

Comment created by rickdt:

I take the index definition from DBAL/Schema/Comparator:207

$table1Indexes = $table1->getIndexes();
$table2Indexes = $table2->getIndexes();
@doctrinebot commented on GitHub (Dec 16, 2009): Comment created by rickdt: I take the index definition from DBAL/Schema/Comparator:207 ``` $table1Indexes = $table1->getIndexes(); $table2Indexes = $table2->getIndexes(); ```
Author
Owner

@doctrinebot commented on GitHub (Dec 16, 2009):

Comment created by @beberlei:

Which database platform is this happening on?

@doctrinebot commented on GitHub (Dec 16, 2009): Comment created by @beberlei: Which database platform is this happening on?
Author
Owner

@doctrinebot commented on GitHub (Dec 16, 2009):

Comment created by rickdt:

mysql

@doctrinebot commented on GitHub (Dec 16, 2009): Comment created by rickdt: mysql
Author
Owner

@doctrinebot commented on GitHub (Dec 19, 2009):

Comment created by @beberlei:

Ok so Mysql creates an index for each foreign key implicitly which is then queryable explicitly.

To fix this the schema comparator "FixSchema" visitor accompanies for that for the MySQL Platform. Do you use your own platform maybe?

@doctrinebot commented on GitHub (Dec 19, 2009): Comment created by @beberlei: Ok so Mysql creates an index for each foreign key implicitly which is then queryable explicitly. To fix this the schema comparator "FixSchema" visitor accompanies for that for the MySQL Platform. Do you use your own platform maybe?
Author
Owner

@doctrinebot commented on GitHub (Dec 19, 2009):

Comment created by @beberlei:

You could really help me if you could paste the serialized object code for both schema instances for your use-case or a reproduce case.

@doctrinebot commented on GitHub (Dec 19, 2009): Comment created by @beberlei: You could really help me if you could paste the serialized object code for both schema instances for your use-case or a reproduce case.
Author
Owner

@doctrinebot commented on GitHub (Dec 21, 2009):

Comment created by rickdt:

Here are the serialized schema you required.

@doctrinebot commented on GitHub (Dec 21, 2009): Comment created by rickdt: Here are the serialized schema you required.
Author
Owner

@doctrinebot commented on GitHub (Dec 21, 2009):

Comment created by rickdt:

I only use Doctrine basic feature, no custom platform.

@doctrinebot commented on GitHub (Dec 21, 2009): Comment created by rickdt: I only use Doctrine basic feature, no custom platform.
Author
Owner

@doctrinebot commented on GitHub (Feb 3, 2010):

Comment created by rickdt:

Can I do anything to help you resolve this issue. This is really a big annoyance not being able to update existing database.

@doctrinebot commented on GitHub (Feb 3, 2010): Comment created by rickdt: Can I do anything to help you resolve this issue. This is really a big annoyance not being able to update existing database.
Author
Owner

@doctrinebot commented on GitHub (Feb 3, 2010):

Comment created by rickdt:

Attached a test case

Doctrine/Tests/ORM/Functional/Ticket/DDC214Test

@doctrinebot commented on GitHub (Feb 3, 2010): Comment created by rickdt: Attached a test case Doctrine/Tests/ORM/Functional/Ticket/DDC214Test
Author
Owner

@doctrinebot commented on GitHub (Feb 3, 2010):

Comment created by rickdt:

The test case must be run using mysql.

@doctrinebot commented on GitHub (Feb 3, 2010): Comment created by rickdt: The test case must be run using mysql.
Author
Owner

@doctrinebot commented on GitHub (Feb 3, 2010):

Comment created by @beberlei:

hah thats an awesome-ly simple test-case.

thank you very much :-)

@doctrinebot commented on GitHub (Feb 3, 2010): Comment created by @beberlei: hah thats an awesome-ly simple test-case. thank you very much :-)
Author
Owner

@doctrinebot commented on GitHub (Feb 3, 2010):

Comment created by @beberlei:

Yes, i found the issue - however the test-case will not work with me requiring it to have 0 change sqls - there is another bug that is related to not null and default values.

@doctrinebot commented on GitHub (Feb 3, 2010): Comment created by @beberlei: Yes, i found the issue - however the test-case will not work with me requiring it to have 0 change sqls - there is another bug that is related to not null and default values.
Author
Owner

@doctrinebot commented on GitHub (Feb 4, 2010):

Comment created by rickdt:

I did not really intend to do a "clean" unit test. I just wanted allow you reproduce the problem.

Good news you have been able to reproduce the issue.

And again, your great work is really appreciated!

@doctrinebot commented on GitHub (Feb 4, 2010): Comment created by rickdt: I did not really intend to do a "clean" unit test. I just wanted allow you reproduce the problem. Good news you have been able to reproduce the issue. And again, your great work is really appreciated!
Author
Owner

@doctrinebot commented on GitHub (Feb 7, 2010):

Comment created by @beberlei:

This and many more issues have been fixed.

@doctrinebot commented on GitHub (Feb 7, 2010): Comment created by @beberlei: This and many more issues have been fixed.
Author
Owner

@doctrinebot commented on GitHub (Feb 7, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Feb 7, 2010): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Feb 9, 2010):

Comment created by rickdt:

This is VERY VERY VERY Great!!!

I experienced serious perfomance issue with the query (getListTableForeignKeysSql) :

  $sql = "SELECT DISTINCT k.`CONSTRAINT*NAME`, k.`COLUMN_NAME`, k.`REFERENCED_TABLE*NAME`, ".
               "k.`REFERENCED*COLUMN_NAME` /*!50116 , c.update_rule, c.delete*rule */ ".
               "FROM information*schema.key_column*usage k /*!50116 ".
               "INNER JOIN information*schema.referential_constraints c ON k.`CONSTRAINT_NAME` = c.constraint*name AND ".
               "  c.constraint*name = k.constraint*name AND ".
               "  c.table*name = k.table_name */ WHERE k.table*name = '$table'";

I think this is a bug in mysql server (5.1.37-1ubuntu5).

I changed the query a little bit and it work great :

  $sql = "SELECT DISTINCT k.`CONSTRAINT*NAME`, k.`COLUMN_NAME`, k.`REFERENCED_TABLE*NAME`, ".
               "k.`REFERENCED*COLUMN_NAME` /*!50116 , c.update_rule, c.delete*rule */ ".
               "FROM information*schema.key_column*usage k /*!50116 ".
               "INNER JOIN information*schema.referential_constraints c ON k.`CONSTRAINT_NAME` = c.constraint*name AND ".
               "  c.constraint*name = k.constraint*name AND ".
               "  c.table*name = '$table' */ WHERE k.table*name = '$table'";
@doctrinebot commented on GitHub (Feb 9, 2010): Comment created by rickdt: This is VERY VERY VERY Great!!! I experienced serious perfomance issue with the query (getListTableForeignKeysSql) : ``` $sql = "SELECT DISTINCT k.`CONSTRAINT*NAME`, k.`COLUMN_NAME`, k.`REFERENCED_TABLE*NAME`, ". "k.`REFERENCED*COLUMN_NAME` /*!50116 , c.update_rule, c.delete*rule */ ". "FROM information*schema.key_column*usage k /*!50116 ". "INNER JOIN information*schema.referential_constraints c ON k.`CONSTRAINT_NAME` = c.constraint*name AND ". " c.constraint*name = k.constraint*name AND ". " c.table*name = k.table_name */ WHERE k.table*name = '$table'"; ``` I think this is a bug in mysql server (5.1.37-1ubuntu5). I changed the query a little bit and it work great : ``` $sql = "SELECT DISTINCT k.`CONSTRAINT*NAME`, k.`COLUMN_NAME`, k.`REFERENCED_TABLE*NAME`, ". "k.`REFERENCED*COLUMN_NAME` /*!50116 , c.update_rule, c.delete*rule */ ". "FROM information*schema.key_column*usage k /*!50116 ". "INNER JOIN information*schema.referential_constraints c ON k.`CONSTRAINT_NAME` = c.constraint*name AND ". " c.constraint*name = k.constraint*name AND ". " c.table*name = '$table' */ WHERE k.table*name = '$table'"; ```
Author
Owner

@doctrinebot commented on GitHub (Feb 9, 2010):

Comment created by @beberlei:

Patched, and speedy again! Thank you very much.

@doctrinebot commented on GitHub (Feb 9, 2010): Comment created by @beberlei: Patched, and speedy again! Thank you very much.
Author
Owner

@doctrinebot commented on GitHub (Feb 9, 2010):

Comment created by rickdt:

That was fast!

@doctrinebot commented on GitHub (Feb 9, 2010): Comment created by rickdt: That was fast!
Author
Owner

@doctrinebot commented on GitHub (May 25, 2010):

Comment created by @jwage:

The test for this issue is failing for me under mysql.


There was 1 failure:

1) Doctrine\Tests\ORM\Functional\Ticket\DDC214Test::testCompanyModel
Failed asserting that <integer:8> matches expected <integer:0>.

/Users/jwage/Sites/doctrine2-orm/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC214Test.php:77
/Users/jwage/Sites/doctrine2-orm/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC214Test.php:54

FAILURES!
Tests: 736, Assertions: 2260, Failures: 1, Skipped: 6.

Any ideas?

@doctrinebot commented on GitHub (May 25, 2010): Comment created by @jwage: The test for this issue is failing for me under mysql. ``` There was 1 failure: 1) Doctrine\Tests\ORM\Functional\Ticket\DDC214Test::testCompanyModel Failed asserting that <integer:8> matches expected <integer:0>. /Users/jwage/Sites/doctrine2-orm/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC214Test.php:77 /Users/jwage/Sites/doctrine2-orm/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC214Test.php:54 FAILURES! Tests: 736, Assertions: 2260, Failures: 1, Skipped: 6. ``` Any ideas?
Author
Owner

@doctrinebot commented on GitHub (Jun 6, 2010):

Comment created by romanb:

Seems to fail under postgres, too.

@doctrinebot commented on GitHub (Jun 6, 2010): Comment created by romanb: Seems to fail under postgres, too.
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2015):

Imported 1 attachments from Jira into https://gist.github.com/547fce46a528d6137bc7

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 1 attachments from Jira into https://gist.github.com/547fce46a528d6137bc7 - [10343_DDC214Test.php](https://gist.github.com/547fce46a528d6137bc7#file-10343_DDC214Test-php)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#267