2017-10-25 4 views
1

SO dieser Code meine Migration istJSONB nicht in Laravel unterstützt

<?php 

use Illuminate\Support\Facades\Schema; 
use Illuminate\Database\Schema\Blueprint; 
use Illuminate\Database\Migrations\Migration; 

class ChangeDataTemplateOfActionTableToJsonB extends Migration 
{ 

    public function __construct() 
    { 
     DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('jsonb', 'string'); 
    } 

    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 


    public function up() 
    { 
     // 
     Schema::table('actions', function ($table) { 
      $table->jsonb('data_template')->change(); 
     }); 
    } 

    /** 
    * Reverse the migrations. 
    * 
    * @return void 
    */ 
    public function down() 
    { 
     // 
    } 
} 

Auch wenn ich die Lehre richtig bin Registrierung es diesem Fehler Würfen enter image description here

ERROR

[Doctrine\DBAL\DBALException]                                            
    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\Typ 
    es\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#registerDoctrineTypeMapp 
    ing() 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. 
+0

https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors –

+0

@AlexBlex in Ordnung – Vikram

Antwort

0

Try Um die DoctrineSchemaManager aus der Schema-Verbindung zu erhalten, registrieren Sie die Zuordnung wie folgt :

$databasePlatform = Schema::getConnection() 
          ->getDoctrineSchemaManager() 
          ->getDatabasePlatform(); 
$databasePlatform->registerDoctrineTypeMapping('jsonb', 'string'); 

Ps: wenn es nicht in den __construct fügen Sie den obigen Code zu dem up Verfahren arbeiten.

+0

nicht überall Mann :( – Vikram

+0

Ok einen Blick auf diese Arbeit [Thema ] (https://coderwall.com/p/mo1gew/custom-datatype-in-laravel-schema-builder) Wenn es funktioniert, kann ich die Antwort aktualisieren :) – Maraboc