4

I have an application on production, and I need to change length of a string column to 280 (as the default is 255).

  • Is it safe for changing it to string to 280?

  • In my local, using MySQLWorkbench, the string column was showing as VARCHAR(255) - I edited it to VARCHAR(280) from MySQLWorkbench, and it seems to work that way in my local, however is this safe to do that in production or should I make use the migration way (Schema builder) like this:

    Schema::table('posts', function ($table) {
      $table->string('text', 280)->change();
    });
    
  • Also the migration way wouldn't remove the existing rows, right?

senty
  • 12,385
  • 28
  • 130
  • 260
  • 1
    This was helpful for me: `Schema::defaultStringLength(191);` See http://stackoverflow.com/a/23786522/470749 and https://laravel-news.com/laravel-5-4-key-too-long-error – Ryan Nov 13 '18 at 03:03

1 Answers1

2
  • Yes, this will change the data type only, since the data is compatible no advanced migration is needed. If it went from 280 to 255, you needed to take the length into consideration.
  • No, the migration will update the current column, because of the ->change() method call.
  • This requires mysql 5.0.3 or above, where varchar got extended to hold more data.

The normal process of testing the migration is to export the Production database to an local environment and then running the migration and see what happens.

mrhn
  • 17,961
  • 4
  • 27
  • 46