Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

331
Visualizações
doctrine altering uuid column on every migration

i have a question if anybody faced this kind of issue. Ive been searching for solution but i didn't find.

Every time i generate migration with doctrine, i see in migration files:

public function up(Schema $schema): void
{
  $this->addSql('ALTER TABLE verification ALTER id TYPE UUID');
  $this->addSql('ALTER TABLE verification ALTER id DROP DEFAULT');
}


public function down(Schema $schema): void
{
  $this->addSql('ALTER TABLE verification ALTER verification_id TYPE UUID');
  $this->addSql('ALTER TABLE verification ALTER verification_id DROP DEFAULT');
}

these are my annotations:

use Ramsey\Uuid\Doctrine\UuidGenerator;

/**
 * @ORM\Id
 * @ORM\Column(type="uuid", unique=true)
 * @ORM\GeneratedValue(strategy="CUSTOM")
 * @ORM\CustomIdGenerator(class=UuidGenerator::class)
 *
 * @Groups({"read"})
 **/
 private UuidInterface $id;

I use postgress image: postgres:13-alpine and "doctrine/doctrine-migrations-bundle": "^3.0",

framework "api-platform/core": "^2.6",

I've tried previous versions of doctrine-migrations-bundle along with postgres:12

Those alters are being added on every migration. I've checked my local db, drop it, remove docker volumes. Then i start containers again, run migration to be sure i got correct db schema. Problem still occurs. I don't know what cause this issue. Maybe some of you have some idea what i can look for?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You probably have 1.7.0 version of ramsey/uuid-doctrine extension in your composer.lock, because it really has a bug with generating schema. Which was fixed a just few days ago: https://github.com/ramsey/uuid-doctrine/pull/165

So try downgrading to 1.6.0:

composer require ramsey/uuid-doctrine:1.6.0

(or upgrading to the latest dev version)

Explanation

The reason why doctrine keeps generating migration for altering the uuid column, is that the custom type class (which is Ramsey\Uuid\Doctrine\UuidType) misses the requiresSQLCommentHint flag (in 1.7.0):

    /**
     * {@inheritdoc}
     *
     * @param AbstractPlatform $platform
     *
     * @return bool
     */
    public function requiresSQLCommentHint(AbstractPlatform $platform)
    {
        return true;
    }

This flag tells doctrine to use a comment on the field to determine which custom type the values from this field need to be hydrated into. In case of Ramsey UuidType the comment should look like this: (DC2Type:uuid)

As a quick workaround, you can even just add the comment manually (without upgrading the ramsey/uuid-doctrine package):

   COMMENT ON COLUMN verification.id IS '(DC2Type:uuid)'

or via migration:

   $this->addSql('COMMENT ON COLUMN verification.id IS \'(DC2Type:uuid)\'');
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda