Wednesday, March 8, 2017

How to migration change columns type?

I got an error, When I try to column type from string to text, With migration function of Laravel.

File : {data_time}_change_db_structure.php

public function up()
  {
    Schema::table('service_request_type', function (Blueprint $table) {
      $table->dropIndex(['sro_key_group']);

      $table->text('sro_key_group')->change();
      $table->renameColumn('sro_key_group', 'tags');
    });
  }

This is orginal migration create table file.

public function up()
  {
    Schema::create('service_request_type', function (Blueprint $table) {
      $table->engine = 'InnoDB';
      ...
      $table->string('sro_key_group', 100)->nullable()->index();
      ...
    });
  }

Error I got.

[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TEXT column 'sro_key_group' used in key specification without a key length (SQL: ALTER TABLE service_request_type CHANGE sro_key_group sro _key_group TEXT DEFAULT NULL COLLATE utf8_unicode_ci)

                                                                                                                                          [Doctrine\DBAL\Driver\PDOException]                                   

SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TEXT column 'sro_key_group' used in key specification without a key length

                                                                                                                                          [PDOException]                                                        

SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TEXT column 'sro_key_group' used in key specification without a key length

What wrong? And I already install doctrine/dbal in my composer.json.



via ThunderBirdsX3

Advertisement