vendredi 23 septembre 2016

Rename column on Laravel 5.1 migration [SQL SERVER][Linux]

I'm writting a migration on Laravel 5.1 and after created a table I rename the table name and the columns, It works running the migration for a MySQL database but on SQL Server 2008 fails trying to rename the columns and outputs the next error:

Next Doctrine\DBAL\DBALException: An exception occurred while executing 'SELECT    col.name,
                     type.name AS type,
                     col.max_length AS length,
                     ~col.is_nullable AS notnull,
                     def.definition AS [default],
                     col.scale,
                     col.precision,
                     col.is_identity AS autoincrement,
                     col.collation_name AS collation,
                     CAST(prop.value AS NVARCHAR(MAX)) AS comment -- CAST avoids driver error for sql_variant type
           FROM      sys.columns AS col
           JOIN      sys.types AS type
           ON        col.user_type_id = type.user_type_id
           JOIN      sys.objects AS obj
           ON        col.object_id = obj.object_id
           JOIN      sys.schemas AS scm
           ON        obj.schema_id = scm.schema_id
           LEFT JOIN sys.default_constraints def
           ON        col.default_object_id = def.object_id
           AND       col.object_id = def.parent_object_id
           LEFT JOIN sys.extended_properties AS prop
           ON        obj.object_id = prop.major_id
           AND       col.column_id = prop.minor_id
           AND       prop.name = 'MS_Description'
           WHERE     obj.type = 'U'
           AND       (obj.name = 'roles' AND scm.name = SCHEMA_NAME())':

I need that the migration working on both databases. My migration code is:

public function up()
{
  Schema::create('cat_tipo_usuario', function (Blueprint $table) {
      $table->increments('id_tipo_usuario');
      $table->string('txt_tipo_usuario');
      $table->timestamps();
  });
  //Se renombra la tabla
  Schema::rename('cat_tipo_usuario','roles');
  //Se cambia el nombre de las columnas
  Schema::table('roles',function($tabla){
    $tabla->renameColumn('id_tipo_usuario','id');
    $tabla->renameColumn('txt_tipo_usuario','nombre');
  });
}

If I comment the lines where I rename the columns the migration runs correctly, so the driver and the connection are working well.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire