Dbal: Column altering in migration from TEXT to LONGTEXT may not apply.

Created on 30 Nov 2016  路  18Comments  路  Source: doctrine/dbal

Based on this
https://github.com/laravel/framework/issues/12363
and my experience here
https://laracasts.com/discuss/channels/laravel/alter-table-change-field-to-longtext

I think there is a problem when migrating a table column from TEXT to LONG TEXT

Bug Missing Tests Schema Schema Comparison Schema Introspection Type Mapping

Most helpful comment

I found another workaround. Just change the column comment, for example:

$table->mediumText('myColumn')->comment(' ')->change(); // up
$table->text('myColumn')->comment('')->change(); // down

Works perfectly on Ubuntu 18.04, PHP 7.2, MySQL 8, Laravel 5.8

All 18 comments

@janokary what RDBMs does this apply to? Maybe this is missing schema introspection?

It is allways mysql

version: 5.5.52-0+deb8u1

or

version: 5.7.11-log

or

version: 5.7.12-0ubuntu1.1

@janokary I need more information. What is the Doctrine DBAL type before and what should it be after? Also length property is significant.

Hi all, I'm facing same issue, using Laravel 5.4, doctrine/dbal v2.5.12, php 5.6.30, mysql Ver 14.14 Distrib 5.6.33.

before: $table->text('body') alter using: $table->longText('body')->change().

The column type should be longtext, but the column type is unchanged.

@ariews can this be reproduced with DBAL-only?

Any news on getting this integrated?

@frandieguez this needs a test case first.

@Ocramius I can see that the solution presented at https://github.com/Cheezykins/dbal/commit/c119353f7832cd4da2003b0ce388f7727e3fcfa9 contains a test case. Does this solution is "good enought"?

I'm quite interested on getting this merged, even if I can help in some way.

Can't find a PR for that: can you open or dig up one?

@Ocramius here's your PR.

I came across this issue trying to change a column in a Laravel application from text to longtext. I traced the migration and the issue was that the change was ignored since $changedProperties was empty although the _length was different (65535 on $table1 vs 16777216 on $table2) .
The creation migration in Laravel was like this:

Schema::create('myTable', function (Blueprint $table) {
    $table->increments('id');
    $table->text('myColumn')->nullable();
});

and the change migration like this:

Schema::table('myTable', function (Blueprint $table) {
    $table->longText('myColumn')->change();
});

I have added some comments on my PR. There's an issue with a failing test which i feel is not well defined.
Please have a look and let me know if i'm missing something..

Any movement on this? Currently experiencing this problem, and google brought me to this github issue created over 2 years ago... !

Some helpful fellow has suggested this workaround, for those who come after me:

https://github.com/laravel/framework/issues/21847#issuecomment-454728171

tldr; change to string column with length > 16777216, since it exceeds varchar max length the column gets converted to longtext. Hacky, but it works.

I found another workaround. Just change the column comment, for example:

$table->mediumText('myColumn')->comment(' ')->change(); // up
$table->text('myColumn')->comment('')->change(); // down

Works perfectly on Ubuntu 18.04, PHP 7.2, MySQL 8, Laravel 5.8

I found another workaround. Just change the column comment, for example:

$table->mediumText('myColumn')->comment(' ')->change(); // up
$table->text('myColumn')->comment('')->change(); // down

Works perfectly on Ubuntu 18.04, PHP 7.2, MySQL 8, Laravel 5.8

I am using the same method to solve the problem. That works.

Ran across this after trying to diagnose the problem for the last hour. Both hacks work. Fixing $table->longText()->change() would be even better.

I found another workaround. Just change the column comment, for example:

$table->mediumText('myColumn')->comment(' ')->change(); // up
$table->text('myColumn')->comment('')->change(); // down

Works perfectly on Ubuntu 18.04, PHP 7.2, MySQL 8, Laravel 5.8

this works as well on ubuntu 16.04, php 7.0 and mariadb 10.2.8, Laravel 5.4

Was this page helpful?
0 / 5 - 0 ratings