0

I wanted to change a column type from integer to timestamp with new migration, but when I try to migrate it doesnt work and it shows an error

Doctrine\DBAL\Exception : 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. I could migrate other migrations that have timestamp datatype but without change() function, so the problem is when using change() with timestamp data type.

I tried to do whats laravel 8 documentation suggests here but still getting the same error, any advice how to solve this issue. I am using laravel 6.

migration up function:

public function up()
    {
        Schema::table('testassignment', function (Blueprint $table) {
            $table->timestamp('duration')->nullable()->change();
        });
    }
Dr.Noob
  • 319
  • 6
  • 17
  • It appears that while what the L8 documentation suggestion works. It only works for L8 and above so if you really must use timestamps then either upgrade or do a raw query that alters your table – apokryfos Sep 16 '21 at 12:20
  • @apokryfos thanks, yes with laravel 8 it should work but I'm using La6, what do u mean to alter my table, like delete the whole table and creating it again, or something else? – Dr.Noob Sep 16 '21 at 12:48
  • @zahidhasanemon thanks, it seems to be the same question – Dr.Noob Sep 16 '21 at 12:50
  • Instead of using `Schema::table`... you could also do `DB::statement('ALTER TABLE testassignment MODIFY duration TIMESTAMP)` and to rollback you do the reverse (note I haven't tested this but I don't see why it wouldn't work). – apokryfos Sep 16 '21 at 12:59

0 Answers0