DDC-993: Cookbook: Overriding the ID Generator during a database migration #1238

Open
opened 2026-01-22 13:06:53 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Jan 19, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user felicitus:

If you need to override the ID Generator, e.g. during a migration, you can do that in your migration script as follows:

{panel:title=Overriding the ID generator}
$em->getClassMetadata('foo\bar\Entity')->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
$em->getClassMetadata('foo\bar\Entity')->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE'));
{panel}

Make sure that both calls equal to the same generator type. You can now modify the @Id fields in your entities. Additionally, make sure that you set the IdGenerator after you created the database using e.g. SchemaTool->create().

Originally created by @doctrinebot on GitHub (Jan 19, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user felicitus: If you need to override the ID Generator, e.g. during a migration, you can do that in your migration script as follows: {panel:title=Overriding the ID generator} $em->getClassMetadata('foo\bar\Entity')->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator()); $em->getClassMetadata('foo\bar\Entity')->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE')); {panel} Make sure that both calls equal to the same generator type. You can now modify the @Id fields in your entities. Additionally, make sure that you set the IdGenerator **after** you created the database using e.g. SchemaTool->create().
admin added the Documentation label 2026-01-22 13:06:53 +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#1238