Skip to content


DDC-1137: SchemaTool#getUpdateSchemaSql() does not respect database identifier in table names #1736

doctrinebot opened this Issue · 2 comments

2 participants


Jira issue originally created by user hlomas:

Given two databases, 'foo' and 'bar', with entities in /Entities/Foo/ annotated as follows:

 * Test
 * @Table(name="foo.test")
 * @Entity

Create an EntityManager instance with
$connectionOptions = array(
'dbname' => 'Foo',
'driver' => 'pdo_mysql',

Use EntityManager#getClassMetaData( "Entities\Foo\Test" ) to pass to SchemaTool#createSchema() and Doctrine appropriately creates a database table foo.test

Use EntityManager#getClassMetaData( "Entities\Foo\Test" ) to pass to SchemaTool#updateSchema() and Doctrine fails with Exception
-> SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'test' already exists

die( print*r( $fromSchema, 1 ) . print_r( $toSchema, 1 ) . print*r( $schemaDiff, 1 ) );
into Doctrine/ORM/Tools/SchemaTool.php line 632 shows $fromSchema outputs
[_tables:protected] => Array

but $toSchema outputs

[_tables:protected] => Array

which causes $schemaDiff to output

[newTables] => Array

In summary, Doctrine/DBAL/Schema/Comparator considers foo.test a new table, because Doctrine/DBAL/Schema/AbstractSchemaManager lists its table as "test" rather than "foo.test".


Comment created by hlomas:

It seems that changing AbstractSchemaManager.php to the following corrected the issue for me, however I am not sure of any repercussions that may arise as a result, being unfamiliar with the codebase.

{panel:title=Doctrine/DBAL/Schema/AbstractSchemaManager.php line 228|borderStyle=solid}
return new Table( $tableName, $columns, $indexes, $foreignKeys, false, array());

{panel:title=Doctrine/DBAL/Schema/AbstractSchemaManager.php line 228|borderStyle=solid}
return new Table( {color:green}$this->_conn->getDatabase() . "." . {color} $tableName, $columns, $indexes, $foreignKeys, false, array());


Comment created by @beberlei:

Multi databases are not supported by schema manager and schema tool yet.

@beberlei beberlei was assigned by doctrinebot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.