Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error changing column type to json #11095

Closed
PhiloNL opened this issue Nov 27, 2015 · 3 comments
Closed

Error changing column type to json #11095

PhiloNL opened this issue Nov 27, 2015 · 3 comments

Comments

@PhiloNL
Copy link
Contributor

PhiloNL commented Nov 27, 2015

Not sure if it's a bug, but when changing a column type from varchar to json results in the following error:

Schema::table('fields', function (Blueprint $table) {
    $table->json('label')->change();
});
  [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(). If this error occurs during database introspecti
  on then you might have forgot to register all database types for a Doctrine Type. Use Abst
  ractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMap
  pedDatabaseTypes(). If the type name is empty you might have a problem with the cache or f
  orgot some mapping information.

Use $table->text('label')->change(); instead?

@edcs
Copy link
Contributor

edcs commented Nov 28, 2015

The problem lies with Doctrine DBAL, it doesn't support the JSON column type for MySQL yet:

https://github.com/doctrine/dbal/blob/2.0.x/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php#L598

I can't see any PRs for it at the moment, but you can add custom map types (as suggested in the error message):

http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/cookbook/custom-mapping-types.html

@victoragung
Copy link

I'm getting this error even though I'm using a PostgreSQL database using Laravel 5.3

@nausmani
Copy link

$query = "ALTER TABLE fields MODIFY label JSON DEFAULT NULL";
\Illuminate\Support\Facades\DB::statement($query);

Try this in laravel migration.. working for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants