Framework: Unknown column type "timestamp" requested

Created on 23 Nov 2016  路  5Comments  路  Source: laravel/framework

  • Laravel Version: 5.3.24
  • PHP Version: 7.0.12
  • Database Driver & Version: 10.1.19-MariaDB

Description:

When trying to update a column with the type of timestamp, it fails with this exception:

[Doctrine\DBAL\DBALException]
  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\DB
  AL\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#registerDoctrine
  TypeMapping() 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.

Steps To Reproduce:

  1. Get clean install of Laravel running laravel new migration-test
  2. Make new migration file php artisan make:migration test --table=users
  3. Add this line of code to it: $table->timestamp('created_at')->change();
  4. Run php artisan migrate

FIX

Doctrine refuses to support MySQL-specific column types like this. So therefor I created a Laravel Package to fix it.

Most helpful comment

I wanted to change all timestamps to nullable as due to the change in how the timestamp column type acts, I'm unable to perform migrations. I decided to attempt to change the columns but I'm told that I need to install doctrine/dbal. After doing so, it tells me timestamp isn't a valid column type.

So as a result, I have to change each column manually as I can't use a migration to do so.

What's the deal with this? I need to take a break because I'm fuming that not only did MySQL implement a breaking change but Laravel won't even let you rectify the issue.

All 5 comments

This is an issue with doctrine, if you check the issues history in this repo you'll find many similar reports, it all depends on what doctrine supports/haven't supported yet/won't support.

I wanted to change all timestamps to nullable as due to the change in how the timestamp column type acts, I'm unable to perform migrations. I decided to attempt to change the columns but I'm told that I need to install doctrine/dbal. After doing so, it tells me timestamp isn't a valid column type.

So as a result, I have to change each column manually as I can't use a migration to do so.

What's the deal with this? I need to take a break because I'm fuming that not only did MySQL implement a breaking change but Laravel won't even let you rectify the issue.

@JTallis As @themsaid says, this is an issue with doctrine/dbal, not with Laravel itself.

For those who installed the Package created by OP and wanted to change a timestamp into nullable (just like I did) like:

$table->timestamp('ClaimedAt')->nullable()->change();

and encountered this error:

Syntax error or access violation: 1067 Invalid default value for 'ClaimedAt' (SQL: ALTER TABLE my_table CHANGE ClaimedAt ClaimedAt TIMESTAMP NULL DEFAULT 'CURRENT_TIMESTAMP')

All you have to do is add a default value:

 $table->timestamp('ClaimedAt')->nullable()->default(null)->change();

and it should work.

Reverting it from nullable to use the current timestamp doesn't need to call default tho:

$table->timestamp('ClaimedAt')->nullable(false)->change();

should work.

Just sharing it here just in case someone is searching for the same question.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

progmars picture progmars  路  3Comments

felixsanz picture felixsanz  路  3Comments

kerbylav picture kerbylav  路  3Comments

gabriellimo picture gabriellimo  路  3Comments

JamborJan picture JamborJan  路  3Comments