-1

Cant seem to upload a laravel database to a live server because of the specified key is too long. SQL ERROR example shows that the key constraint is too long, however it is not just on one table it is on many. Is there a way to update this or change my DB to be able to upload it? I followed the guide in the app service provider but i am not sure if I have to drop the DB, then migrate again with the key constraint on the boot() method on the app service provider. Please help.

m33bo
  • 1,334
  • 1
  • 17
  • 34

2 Answers2

1

In fact the adding defaultStringLength to the boot method does work however because I was using vendor scripts, I could not rollback my migrations as the migrations were created by the BREAD Controller in Voyager. In order to get the MYSQL import to work, without losing data or rolling and changing the migrations I had to manually, with Sequel Pro or whatever you are using, and change manually each varchar('255') to varchar('191').

This saved me from deleting and having to rollback.

Adding:

use Illuminate\Support\Facades\Schema; // add this 

Schema::defaultStringLength(191);

to the AppServiceProvider.php will work from now on because any other migration I create with the BREAD controller will have the default 191 added to the string length.

For reference: https://laravel-news.com/laravel-5-4-key-too-long-error

m33bo
  • 1,334
  • 1
  • 17
  • 34
0

add defaultStringLength to boot method of AppServiceProvider

use Illuminate\Support\Facades\Schema; // add this 

Schema::defaultStringLength(191);

rollback migrations and try again after adding this line. It will work.

Jigar Shah
  • 6,143
  • 2
  • 28
  • 41
  • just concerned at doing it, reuploading the data, and the same problem arising because of the saved sql state – m33bo Jun 16 '17 at 12:05
  • I had done this before so I can tell you that it will work properly. Just rollback your migration files and try again. It's fresh laravel setup? – Jigar Shah Jun 16 '17 at 12:06
  • you can have a look at this issue: https://github.com/laravel/framework/issues/17508 – Jigar Shah Jun 16 '17 at 12:08
  • no its not fresh its a project and i am using voyager package so makes it more tricky as they have their own migrations so currently getting errors on rollback. – m33bo Jun 16 '17 at 12:10
  • Thanks though. I think it will work just need to tinker the setup – m33bo Jun 16 '17 at 12:10