1
votes

I created a migration to update the size of a VARCHAR column in MySQL and to rename it in the same migration. So to change a VARCHAR() type through Laravel Schema we use string() base on Laravel docs

This is the function up():

Schema::table('address', function (Blueprint $table) {
    $table->string('place_id', 100)->change();
    $table->renameColumn('place_id', 'full_address');
});

and the function down():

Schema::table('address', function (Blueprint $table) {
    $table->string('full_address', 255)->change();
    $table->renameColumn('full_address', 'place_id');
});

It is renaming the column but it is not changing the size, any ideas why?.

MySQL table

Field, table, Type, Character Set, Display Size
place_id,address,VARCHAR,utf8,255

Thank you in advance.

1
what exactly do you mean by "it's not working" - Philipp Sander
What's the php artisan ... command you're running? - Tim Lewis
I updated the question. I am running php artisan migrate, and migrate:rollback. I dunno if it's possible to change the size and rename the column in the same migration. - CarlosZ
What does the table look like after you run migrate and before you run migrate:rollback? - James Cook
This was helpful for me: Schema::defaultStringLength(191); See stackoverflow.com/a/23786522/470749 and laravel-news.com/laravel-5-4-key-too-long-error - Ryan

1 Answers

0
votes

I found a solution, I am not sure if it's the best one, but it is better to use multiple Schemas.

Schema::table('address', function (Blueprint $table) {
  $table->string('place_id', 100)->change();
});

Schema::table('address', function (Blueprint $table) {
  $table->renameColumn('place_id', 'full_address');
});