Some background about my application:
Problem: if I run a command migrations:diff
to generate migration from changes in my entity classes, I get the following exception:
[Doctrine\DBAL\DBALException] Unknown column type "json" 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().
The problem was because old column in database had a comment (DC2Type:json)
. I changed it to (DC2Type:json_array)
and it works.
Why this problem occur? While doctrine is calculating the DIFF between entity mappings with database columns and actual database columns, Doctrine parses MySQL column comment ((DC2Type:json)
) and validates json
type. Since from newer Doctrine versions, you must use json_array
instead of json
, Doctrine library throws an exception.
The issue is that doctrine/dbal
version 2.5.x
had no support for JSON fields in MySQL.
Bump the version of doctrine/dbal
in your composer.json
to ^2.6
and it should work. Make sure to check for compatibility-breaking changes in the release changelog