Skip to content

Loading…

DDC-815: Identifier quoting does not work with unique columns in PostgreSQL #5333

Closed
doctrinebot opened this Issue · 3 comments

1 participant

@doctrinebot

Jira issue originally created by user zyxist:

It seems that Doctrine ORM tries to generate invalid unique index names, when the table name is quoted and one of the columns uses the "unique" annotation:

/****
 * Users\User
 *
 * @Table(name="`User`")
 * @Entity
 */
class User
{
    /****
     * @var string $login
     *
     * @Column(name="login", type="string", length=40, unique=true)
     */
    protected $login;

Expected result:

The table gets created.

Actual result:

Creating database schema...
Doctrine\DBAL\Schema\SchemaException
Invalid index-name "User"*login_uniq given, has to be [a-zA-Z0-9*]
/.../Doctrine/DBAL/Schema/SchemaException.php
Line 33
Trace:
        0. Doctrine\DBAL\Schema\SchemaException::indexNameInvalid on line 214
        1. Doctrine\DBAL\Schema\Table::_createIndex on line 176
        2. Doctrine\DBAL\Schema\Table::addUniqueIndex on line 341
        3. Doctrine\ORM\Tools\SchemaTool::_gatherColumn on line 273
        4. Doctrine\ORM\Tools\SchemaTool::_gatherColumns on line 193
        5. Doctrine\ORM\Tools\SchemaTool::getSchemaFromMetadata on line 93
        6. Doctrine\ORM\Tools\SchemaTool::getCreateSchemaSql on line 76
        7. Doctrine\ORM\Tools\SchemaTool::createSchema on line 73
        8. Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand::executeSchemaCommand on line 59
        9. Doctrine\ORM\Tools\Console\Command\SchemaTool\AbstractCommand::execute on line 159
        10. Symfony\Component\Console\Command\Command::run on line 205
        11. Symfony\Component\Console\Application::doRun on line 117
        12. Symfony\Component\Console\Application::run on line 72

I don't know whether the problem is caused by ORM which forgets that the table names can be quoted, or by DBAL for the same reason. Anyway, I think this should be fixed. I agree with your argumentation that identifier quoting can be wrong, but you should also remember that Doctrine can be used in cooperation with other ORM libraries or with legacy databases. I am in this particular situation: the database is shared by two different systems written in two different languages and using two different ORM libraries, and this is a big limitation for me.

@doctrinebot

Comment created by @beberlei:

  1. Why do you need SchemaTool if you have a legacy database?

  2. You can use @Table(uniqueConstraints=...) to specify the index name, this circumvents your problem http://www.doctrine-project.org/projects/orm/2.0/docs/reference/annotations-reference/en#ann_table

@doctrinebot

Comment created by @beberlei:

This issue has a simple workaround and no possible sane solution undoing the quoting.

@doctrinebot

Issue was closed with resolution "Won't Fix"

@doctrinebot doctrinebot added this to the 2.0-RC1 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
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.