Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

andreladocruz's avatar

Uuid type change to nullable through migrations not working

Hi friends, I'm using uuids as id in application. I'm trying to change an uuid column to be nullable and i'm getting the following error:

[Doctrine\DBAL\DBALException]                                                                                                                                                     
  Unknown column type "uuid" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types w  
  ith \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database introspection then you might have forgot to register all database types for a Doctrine Type.   
  Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes(). If the type name is empty you might have a problem with th  
  e cache or forgot some mapping information.

here is my migration code:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class SetAffiliateIdToNullableInTransactions extends Migration
{
  /**
   * Run the migrations.
   *
   * @return void
   */
  public function up()
  {
    Schema::table('transactions', function (Blueprint $table) {
      $table->uuid('affiliate_id')->nullable()->change();
    });
  }

  /**
   * Reverse the migrations.
   *
   * @return void
   */
  public function down()
  {
    Schema::table('transactions', function (Blueprint $table) {
      $table->uuid('affiliate_id')->change();
    });
  }
}

any help?

0 likes
3 replies
mcblum's avatar
mcblum
Best Answer
Level 2

Doctrine doesn't support UUID fields and that's what you're using when you're running change().

1 like
lostdreamer_nl's avatar

only thing you can do is:

  • add a new nullable uuid column (this goes via Laravel migration instead of the Doctrine/DBAL change() version)
  • update all rows to have the same values in the new column as the old
  • delete the old column
1 like
Markohs's avatar

This is a old conversation but I just achieved this installing a third party package:

composer require ramsey/uuid-doctrine

And on the up() and down() function add:

    \Doctrine\DBAL\Types\Type::addType('uuid', 'Ramsey\Uuid\Doctrine\UuidType');
4 likes

Please or to participate in this conversation.