Dbal: 2.7 breaks renaming columns in mysql 5.7

Created on 6 Apr 2018  路  8Comments  路  Source: doctrine/dbal

I am using this package with latest version of Laravel (5.6.15) and my migrations have started breaking when using $table->renameColumn().

It looks like when I try and rename a nullable column the sql that is generated adds not null. It is also not including UNSIGNED for unsigned integers.

Bug Duplicate Missing Tests

Most helpful comment

+1 on this issue, running Laravel migrations that rename columns with doctrine/dbal 2.7 generates the following error:

SQLSTATE[0A000]: Feature not supported: 1846 ALGORITHM=COPY is not supported. Reason: Columns participating in a fore ign key are renamed. Try ALGORITHM=INPLACE. (SQL: ALTER TABLE watchlist CHANGE user_id watchlist_id INT NOT NULL)

Downgrading to 2.6.3 allows me to run migrations again

Not that this only happens when changing a foreign key column

All 8 comments

What's the DBAL version?

2.7.0

+1 on this issue, running Laravel migrations that rename columns with doctrine/dbal 2.7 generates the following error:

SQLSTATE[0A000]: Feature not supported: 1846 ALGORITHM=COPY is not supported. Reason: Columns participating in a fore ign key are renamed. Try ALGORITHM=INPLACE. (SQL: ALTER TABLE watchlist CHANGE user_id watchlist_id INT NOT NULL)

Downgrading to 2.6.3 allows me to run migrations again

Not that this only happens when changing a foreign key column

I am unsure how to reproduce this using just DBAL since i have only ever used DBAL in conjunction with Laravel but here are some steps to reproduce this with a fresh laravel install.

Here's my original migration creating a table with a foreign key

<?php

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

class AddSomethingToForeignKey extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('foreign_key_test', function (Blueprint $table) {
            $table->unsignedInteger('user_id');

            $table->foreign("user_id")->references('id')->on("users");
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('foreign_key_test');    
    }
}

And here's the migration renaming that column

<?php

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

class TestRenamingForeignKeyColumn extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('foreign_key_test', function (Blueprint $table) {
            $table->renameColumn('user_id', 'user');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('foreign_key_test', function (Blueprint $table) {
            $table->renameColumn('user', 'user_id');
        });
    }
}

Which produces this error

Doctrine\DBAL\Driver\PDOException::("SQLSTATE[0A000]: Feature not supported: 1846 ALGORITHM=COPY is not supported. Reason: Columns participating in a foreign key are renamed. Try ALGORITHM=INPLACE.")
      /Users/ajoy/Documents/EliteAlliance/test_doctrine/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:140

@ajoy39 please try reducing the test to DBAL-only. You can debug the Laravel app and see what calls it makes to Doctrine. AFAIK, no one of the maintainers uses Laravel.

In 2.7.0, unsigned was dropped when renaming an integer column, causing failure due to mismatching foreign key columns. This seems to be working in 2.7.1 again 馃憤

2.7.1 also fixed this for me

Ok, thanks for the info. This was likely fixed by #3089 (assuming you are using the unsigned=true option).
Closing it here then. :+1:

Was this page helpful?
0 / 5 - 0 ratings