2

I am trying to perform a migration and I am getting the following problem.

Unknown column type "timestamp" 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 with \Doctrine\DBAL\Types\Type::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.

My code is the following:

Schema::table('XXXXXXXX', function (Blueprint $table) {
        $table->timestamp('start')->change();
        $table->timestamp('end')->change();
    });

The strange thing is that I have already performed migrations with that type of data:

Schema::create('XXXXXX', function (Blueprint $table) {
        ...
        $table->timestamp('date_expired')->nullable();
        ...

    });

Does anyone know how to fix it or see the error I'm doing.

Thanks


UPDATE

In the end I have deleted the migration, I have modified it putting timestamp in the necessary columns and I have executed it again. (Having deleted the table before from the database)

miken32
  • 42,008
  • 16
  • 111
  • 154

2 Answers2

5

On the laravel docs page you can find a warning telling you that there are certain types that you can't use with the ->change() method.

Link to laravel docs

It also says this:

To modify a timestamp column type a Doctrine type must be registered.

MESP
  • 486
  • 2
  • 17
  • In the end I have deleted the migration, I have modified it putting timestamp in the necessary columns and I have executed it again. (Having deleted the table before from the database) – Agustín Tamayo Quiñones Feb 16 '22 at 09:50
  • @AgustínTamayoQuiñones, to modify a timestamp column type, we can use raw DB queries: `DB::unprepared('alter table users modify created_at timestamp default CURRENT_TIMESTAMP not null;');`. – Roman Grinyov Aug 02 '23 at 20:55
2

For everyone who is still coming across this issue, there currently is an official way to support this. See this part of the docs.

Basically, you need to add the following to your config/database.php file:

use Illuminate\Database\DBAL\TimestampType;
 
'dbal' => [
    'types' => [
        'timestamp' => TimestampType::class,
    ],
],
vinhtranchau
  • 565
  • 2
  • 13