Laravel-ide-helper: Unknown database type json requested, PostgreSqlPlatform may not support it.

Created on 18 Mar 2016  路  11Comments  路  Source: barryvdh/laravel-ide-helper

First of all, thank you for creating this utility, it definitely makes my life easier!

I recently added a JSON column to one of my PostgreSQL powered databases. While Laravel and Postgres natively supports JSON, executing the artisan command ./artisan ide-helpder:models crashes with the following exception:

Exception: Unknown database type json requested, Doctrine\DBAL\Platforms\PostgreSqlPlatform may not support it.

I guess this may be related to an outdated Doctrine version? Any chance to get this working?

Most helpful comment

Hi Hohl,
fix this by doing a...

php artisan vendor:publish

which will create a config/ide-helper.php file.

Modify this file and change the bottom of the file to read:
'custom_db_types' => array(
'postgresql' => array(
"jsonb" => "json_array",
"json" => "json_array"
)
)

I think thats all you need to do.

All 11 comments

Hi Hohl,
fix this by doing a...

php artisan vendor:publish

which will create a config/ide-helper.php file.

Modify this file and change the bottom of the file to read:
'custom_db_types' => array(
'postgresql' => array(
"jsonb" => "json_array",
"json" => "json_array"
)
)

I think thats all you need to do.

@barryvdh , can you verify @securit 's solution and implement it if it proves working?

@shehi. The point here is that @barryvdh has already implemented this. I simply pointed you in the direction of using what he had already developed.
Happy coding :)

Yes but I'd be happy to provide some better default mappings, that are missing from Doctrine but common in Laravel. Feel free to submit a PR to the config file.

@securit : Oh, man, sorry. I am sleeping. You show how to edit config file, not any of generated meta files. My bad.

So, who is submitting this PR for default config file? I haven't used JSON types in Db, so don't want to mess something in there.

I have the same problem on dbal 2.5 and 2.6. The fix provided above is not worked.

Exception: Unknown column type "jsonb" 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 forgott en to register all database types for a Doctrine Type. Use AbstractPlatform#regi sterDoctrineTypeMapping() or have your custom types implement Type#getMappedData baseTypes(). If the type name is empty you might have a problem with the cache o r forgot some mapping information. Could not analyze class App\Model\User.

@gencer Just update your config as described by @securit. At least it worked for me.

@hohl i already did it. If i put exactly what @securit says, i get exactly the error above. If I remove them i get first error mentioned by you. So, somehow this config changes something but not works on my environment.

I use psql-9.6rc1, doctrine-dbal "dev-master". Do you have a specific versions on this? (Note: I saw that doctrine imports 9.4 mapping from 9.4 to 10 so im sure version of db is not the case)

Quick addition:

Line 321: after =>

if(($yourTypeName == 'jsonb' || $yourTypeName == 'json') && $platformName == 'postgresql')
                Type::addType($yourTypeName, '\Doctrine\DBAL\Types\JsonType');

Line 361: after =>

      case 'json_array':
           $type = 'array';
           break;

fixes the problem.

Just wanted to let others know that @securit's solution worked very well for a mysql db with json field. Thank you @securit!

php artisan vendor:publish

which will create a config/ide-helper.php file.

Modify this file and change the bottom of the file to read:

    'custom_db_types' => array(
        'mysql' => [
            'json' => 'json_array',
        ]
    ),

This fixed the error

Exception: Unknown database type json requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it.
Could not analyze class App\User. <- or whatever model this would be in your case

@barryvdh custom_db_types is the solution to such custom datatypes, issue can be closed :}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

celorodovalho picture celorodovalho  路  4Comments

Alymosul picture Alymosul  路  4Comments

marcus-clements picture marcus-clements  路  3Comments

GitzJoey picture GitzJoey  路  4Comments

Gummibeer picture Gummibeer  路  3Comments