Framework: Fehler beim Ändern des Spaltentyps in json

Erstellt am 27. Nov. 2015  ·  3Kommentare  ·  Quelle: laravel/framework

Ich bin mir nicht sicher, ob es sich um einen Fehler handelt, aber das Ändern eines Spaltentyps von varchar in json führt zu folgendem Fehler:

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.

Verwenden Sie stattdessen $table->text('label')->change(); ?

Hilfreichster Kommentar

Ich erhalte diesen Fehler, obwohl ich eine PostgreSQL-Datenbank mit Laravel 5.3 verwende

Alle 3 Kommentare

Das Problem liegt bei Doctrine DBAL, es unterstützt den JSON-Spaltentyp für MySQL noch nicht:

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

Ich kann im Moment keine PRs dafür sehen, aber Sie können benutzerdefinierte Kartentypen hinzufügen (wie in der Fehlermeldung vorgeschlagen):

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

Ich erhalte diesen Fehler, obwohl ich eine PostgreSQL-Datenbank mit Laravel 5.3 verwende

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

Probieren Sie dies in der Laravel-Migration aus. Sie arbeiten für mich

War diese Seite hilfreich?
0 / 5 - 0 Bewertungen

Verwandte Themen

iivanov2 picture iivanov2  ·  3Kommentare

lzp819739483 picture lzp819739483  ·  3Kommentare

RomainSauvaire picture RomainSauvaire  ·  3Kommentare

JamborJan picture JamborJan  ·  3Kommentare

SachinAgarwal1337 picture SachinAgarwal1337  ·  3Kommentare