skip to Main Content

I have a need to create a migration that changes an existing ‘unsignedMediumInteger’ column to nullable().

I have the following in my migration:

<?php

use IlluminateDatabaseMigrationsMigration;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateSupportFacadesSchema;
use AppNewModelsSubscriptionType;

return new class extends Migration
{
    public function up()
    {
        Schema::table('subscription_types', function ($table) {
            $table->unsignedMediumInteger('max_number_of_employees')->nullable()->change();
        });
    }
};

This throws an error as below:

  INFO  Running migrations.  

  2023_10_25_103141_make_subscription_types_max_number_of_employees_field_nullable  108ms FAIL

   DoctrineDBALException 

  Unknown column type "mediuminteger" requested. Any Doctrine type that you use has to be registered with DoctrineDBALTypesType::addType(). You can get a list of all the known types with DoctrineDBALTypesType::getTypesMap(). If this error occurs during database introspection then you might have forgotten 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 the cache or forgot some mapping information.

…any pointers as to get around this please?

Thanks, K…

2

Answers


  1. Try this approach:

    <?php
    
    use IlluminateDatabaseMigrationsMigration;
    use IlluminateSupportFacadesDB;
    
    return new class extends Migration
    {
        /**
         * Run the migrations.
         */
        public function up(): void
        {
            DB::statement("ALTER TABLE <table_name> MODIFY COLUMN <column_name> MEDIUMINT UNSIGNED NULL");
        }
    
        /**
         * Reverse the migrations.
         */
        public function down(): void
        {
            DB::statement("ALTER TABLE <table_name> MODIFY COLUMN <column_name> MEDIUMINT UNSIGNED NOT NULL");
        }
    };
    
    Login or Signup to reply.
  2. The best way is to use DB::statement method to execute a raw SQL statement with the alter query

    use IlluminateDatabaseMigrationsMigration;
    use IlluminateSupportFacadesDB;
    
    return new class extends Migration {
        public function up()
        {
            DB::statement('ALTER TABLE subscription_types MODIFY max_number_of_employees MEDIUMINT UNSIGNED NULL');
        }
    };
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search