Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Column altering in migration from TEXT to LONGTEXT may not apply. #2566

Closed
janokary opened this issue Nov 30, 2016 · 22 comments · Fixed by #4746
Closed

Column altering in migration from TEXT to LONGTEXT may not apply. #2566

janokary opened this issue Nov 30, 2016 · 22 comments · Fixed by #4746

Comments

@janokary
Copy link

Based on this
laravel/framework#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

@Ocramius
Copy link
Member

Ocramius commented Dec 4, 2016

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

@janokary
Copy link
Author

janokary commented Dec 4, 2016

It is allways mysql

version: 5.5.52-0+deb8u1

or

version: 5.7.11-log

or

version: 5.7.12-0ubuntu1.1

@deeky666
Copy link
Member

deeky666 commented Jan 17, 2017

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

@ariews
Copy link

ariews commented May 31, 2017

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.

@Ocramius
Copy link
Member

@ariews can this be reproduced with DBAL-only?

jewei added a commit to jewei/dbal that referenced this issue Oct 11, 2017
@frandieguez
Copy link

Any news on getting this integrated?

@Ocramius
Copy link
Member

Ocramius commented Feb 28, 2018

@frandieguez this needs a test case first.

@frandieguez
Copy link

frandieguez commented Mar 5, 2018

@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.

@Ocramius
Copy link
Member

Ocramius commented Mar 7, 2018

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

cbotsikas added a commit to cbotsikas/dbal that referenced this issue Jun 9, 2018
cbotsikas added a commit to cbotsikas/dbal that referenced this issue Jun 9, 2018
@cbotsikas
Copy link

@Ocramius here's your PR.

@cbotsikas
Copy link

cbotsikas commented Jun 9, 2018

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();
});

@cbotsikas
Copy link

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..

@uphlewis
Copy link

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

@uphlewis
Copy link

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

laravel/framework#21847 (comment)

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

@kl83
Copy link

kl83 commented Apr 5, 2019

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

@ZsgsDesign
Copy link

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.

@lwitzel
Copy link

lwitzel commented Jun 3, 2019

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

@jm-vasquez
Copy link

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

@InsaneSoftware
Copy link

As of today.. this bug is still in laravel..

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

As of today.. this bug is still in laravel and this is the fix..

@holymp2006
Copy link

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

As of today, when changing between text types (text, mediumText, or longText), this is still the fix.

@morozov morozov closed this as completed Jul 9, 2021
@morozov morozov reopened this Jul 9, 2021
@morozov morozov linked a pull request Aug 23, 2021 that will close this issue
@morozov
Copy link
Member

morozov commented Aug 25, 2021

This bug will be covered by the Doctrine\DBAL\Tests\Functional\Schema\MySQL::testLobLengthIncrementOverLimit test in #4746.

Additionally,

$column = new Column('myColumn', new TextType(), [
    'length' => 2**15, // TEXT
]);
$desiredTable = new Table('test', [$column]);

$sm = $connection->createSchemaManager();
$sm->dropAndCreateTable($desiredTable);
echo $connection->fetchNumeric('SHOW CREATE TABLE test')[1], PHP_EOL;

// CREATE TABLE `test` (
//   `myColumn` text COLLATE utf8_unicode_ci NOT NULL
// ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_unicode_ci

$column->setLength(2**24); // LONGTEXT

$actualTable = $sm->listTableDetails('test');

$comparator = $sm->createComparator();
$diff = $comparator->diffTable($actualTable, $desiredTable);
$sm->alterTable($diff);
echo $connection->fetchNumeric('SHOW CREATE TABLE test')[1], PHP_EOL;

// CREATE TABLE `test` (
//   `myColumn` longtext COLLATE utf8_unicode_ci NOT NULL
// ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_unicode_ci

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.