DDC-781: "No identifier/primary key specified for Entity" problem, Doctrine Beta 3 cannot find primary key #960

Open
opened 2026-01-22 12:57:24 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Aug 31, 2010).

Jira issue originally created by user minxuan.guo:

when execute

php doctrine.php orm:convert-mapping --from-database annotation "Entities"

get error message

No identifier/primary key specified for Entity 'Classname(Tablename)'. Every Entity must have an identifier/primary key.

For resolving this problem
I've replaced the line
{quote}
public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
{
...
{color:red}$indexes = $this->tables[$tableName]->getIndexes();{color}
...
}
{quote}
in function "loadMetadataForClass" in \Doctrine\ORM\Mapping\Driver\DatabaseDriver.php by
{quote}
public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
{
...
{color:red}$indexes = $this->_sm->listTableIndexes($tableName);{color}
...
}
{quote}
then the beta 3 works for my date base

It is because doctrine look for $indexes['prime'] to construit the primary key in entities. when we use "$this->tables[$tableName]->getIndexes()", the keys in $indexes are the real name of indexes of the data base, and in my database, the primary key indexes are named PK_TABLENAME. So I have to use $this->_sm->listTableIndexes($tableName) to pre-edit the indexes before get the list

Originally created by @doctrinebot on GitHub (Aug 31, 2010). Jira issue originally created by user minxuan.guo: when execute php doctrine.php **orm:convert-mapping** --from-database annotation "Entities" get error message **No identifier/primary key specified for Entity '<cite>Classname(Tablename)</cite>'. Every Entity must have an identifier/primary key.** For resolving this problem I've replaced the line {quote} public function loadMetadataForClass($className, ClassMetadataInfo $metadata) { ... {color:red}$indexes = $this->tables[$tableName]->getIndexes();{color} ... } {quote} in function "loadMetadataForClass" in \Doctrine\ORM\Mapping\Driver\DatabaseDriver.php by {quote} public function loadMetadataForClass($className, ClassMetadataInfo $metadata) { ... {color:red}$indexes = $this->_sm->listTableIndexes($tableName);{color} ... } {quote} then the beta 3 works for my date base It is because doctrine look for $indexes['prime'] to construit the primary key in entities. when we use "$this->tables[$tableName]->getIndexes()", the keys in $indexes are the real name of indexes of the data base, and in my database, the primary key indexes are named PK_TABLENAME. So I have to use $this->_sm->listTableIndexes($tableName) to pre-edit the indexes before get the list
admin added the Bug label 2026-01-22 12:57:24 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#960