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.
laravel new migration-test
php artisan make:migration test --table=users
$table->timestamp('created_at')->change();
php artisan migrate
Doctrine refuses to support MySQL-specific column types like this. So therefor I created a Laravel Package to fix it.
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.
This is an issue #https://github.com/doctrine/dbal/issues/2558
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.
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.