1

I am new to PHP and laravel platform,need your help to resolve PDOException on run the migration task to alter table column type from number to string.

...
public function up()
{
    Schema::table('BuildTable', function (Blueprint $table) {
       $table->string('snapshot_id')->change();
    });

}
....

getting PDOException on run the migration task

Doctrine\DBAL\Driver\PDOException::("SQLSTATE[0A000]: Feature not supported: 7 ERROR:  unimplemented: type conversion from INT8 to VARCHAR(255) requires overwriting existing values which is not yet implemented
HINT:  You have attempted to use a feature that is not yet implemented.

Existing table structure was created using

      Schema::create(
        $this->tablename,
        function (Blueprint $table) {
            $table->increments('id');
            $table->integer('account_id')->unsigned();
            $table->integer('snapshot_id')->unsigned();
            $table->timestamps(6);
            $table->softDeletes('deleted_at', 6)->default(null);
        }
    );

The existing table already have data in snapshot_id

Php version is 7.3.20 running on linux mint OS , Database - cockroachDB

  • Please read: https://stackoverflow.com/questions/32940495/laravel-migration-table-fields-type-change/40047800 – Chris Aug 05 '20 at 07:13
  • 1
    Does this answer your question? [How to change column data type in laravel 5.6?](https://stackoverflow.com/questions/59451801/how-to-change-column-data-type-in-laravel-5-6) – N69S Aug 05 '20 at 07:35
  • Chris , the details didn't resolve the issue , I am getting "SQLSTATE[0A000]: Feature not supported: 7 ERROR: unimplemented: type conversion from INT8 to VARCHAR(255) requires overwriting existing values which is not yet implemented – Mishi Reghunadh Aug 05 '20 at 07:38
  • I think the error message is fairly self explanatory. Your table already contains data which has been stored as `INT8` and you're asking the engine to convert to `VARCHAR(255)` which it doesn't know how to do. If the table were empty of data it would be different. Why do you want to convert what looks to be a foreign key to a string anyway? – Peppermintology Aug 05 '20 at 08:03
  • This looks like an issue with your database rather than Laravel since the error message is actually from your database itself. Which database you're using? Please the details in your post. – sykez Aug 05 '20 at 08:06
  • 1
    @sykez @ Unflux You are correct,Its a database related issue as I am getting similar exception on direct SQL execution in tool too. We are using cockroachDB and it looks like direct data conversion from INT8 to VARCHAR feature not available for this particular version of it – Mishi Reghunadh Aug 05 '20 at 12:22

1 Answers1

2

This feature will be experimentally available in CockroachDB v20.2, which is getting released later this year.

If you want, you can test out with an alpha version (v20.2.0-alpha.2) which has this functionality. See the release notes. To use it, you need to set the following session variable: SET enable_experimental_alter_column_type_general = true;

rafiss
  • 553
  • 3
  • 14