0

Hey guys i use mysql and when i migrate files in my laravel , it only shows varchar(191) instead of 255 . Because in my local database it appears as a varchar (191 ) but for my production database it appear as a varchar ( 255 ) Whats wrong? Because of not same mysql version ? Thanks.

  • 1
    The migration should copy the table layouts aswell, so if your local db is 191 it will migrate as such. Make sure your local db is correct before migrating, also make sure you have the same version of MySQL installed on both sites. – Havenard Jul 13 '18 at 03:09
  • Make sure you're looking at the right schema and database. – tadman Jul 13 '18 at 03:10
  • Hey @tadman i create a migration file like this $table->string('document')->nullable(); as a default one i did not change any thing. In my database.php 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', Thanks. – KaungKhant Zaw Jul 13 '18 at 03:40

1 Answers1

3

as suggested on comment, 1st step is to check if your local database has default setting of 191 characters and see if your setting allows you to have 255. if everything seems right, you can force 255 by adding the following snippet in App\Providers\AppServiceProvider.php

public function boot()
{
    // add the line below, you can change the value of 255 as necessary.
    Schema::defaultStringLength(255);
}

for a detailed description, check this link. laravel 5.4 specified key was too long, why the number 191

happy coding!

ashish
  • 3,555
  • 1
  • 20
  • 26
  • Hey @ashish how can i check if your local database has default setting of 191 characters and see if your setting allows you to have 255. Thanks. – KaungKhant Zaw Jul 13 '18 at 03:34
  • @KaungKhantZaw if you mysql engine supports utf8mb4 as charset and utf8mb4_unicode_ci as collation, you should be able to use 255 as default. check if your mysql version supports those settings or not. If you are using phpmyadmin, go to the specific database, and check to collation support by clicking on operation tab. also, check the link in the answer as well. Mysql v5.5.3+ should support the mentioned settings. – ashish Jul 13 '18 at 03:47
  • Hello @ashish Thanks for Answer. Yes i used phpmyadmin , and collation are utf8mb4_unicode_ci same as production db and local db . – KaungKhant Zaw Jul 13 '18 at 03:51
  • @KaungKhantZaw, let me correct myself, you should be using MySQL v5.7.7+ to get 255 or these setting to get 255 by default – ashish Jul 13 '18 at 03:54
  • Thanks for the help and effort. And may i know where can i check version of my MySQL ? – KaungKhant Zaw Jul 13 '18 at 04:42
  • if you use console, use mysql -V and if you use phpmyadmin, it should be on the right side of the dashboard – ashish Jul 13 '18 at 16:02