Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Won't Fix
-
Affects Version/s: 2.0-BETA4
-
Fix Version/s: 2.0-RC1
-
Component/s: Mapping Drivers
-
Security Level: All
-
Labels:None
-
Environment:PostgreSQL 8.4
Description
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.
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