mercredi 26 décembre 2018

Migrating mysql5/laravel 5 under docker error Specified key was too long

I try to install my laravel 5.7.19 application under docker and running migration I got error:

Migrating: 2018_01_01_145312_create_settings_table
Specified key was too long
   Illuminate\Database\QueryException  : SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `settings` add unique `settings_name_unique`(`name`))

  at /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668| 

  Exception trace:

where settings defined as :

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateSettingsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('settings', function (Blueprint $table) {
            $table->increments('id')->unsigned();
            $table->string('name', 255)->unique();
            $table->string('value', 255);
            $table->timestamp('created_at')->useCurrent();
            $table->timestamp('updated_at')->nullable();

            $table->index(['created_at'], 'settings_created_at_index');
        });
        Artisan::call('db:seed', array('--class' => 'SettingsWithInitData'));
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('settings');
    }
}

The seeder file which is triggered is Votes/database/seeds/SettingsWithInitData.php, which has rows :

public function run()
{
    DB::table('settings')->insert([
        'name' => 'site_name',
        'value' =>  'Select & Vote',
    ]);

    DB::table('settings')->insert([
        'name' => 'copyright_text',
        'value' =>  '© 2018 - 2018 All rights reserved',
    ]);

    DB::table('settings')->insert([
        'name' => 'elastic_automation',
        'value' =>  'N',
    ]);

None of settings->name field has more 40 chars and I did not have any problems on my lamp system.

In phpmyadmin I created new database with utf8_general_ci.

Checking created table in phpmyadmin I do not see unique index on name field : https://imgur.com/a/2RfeyGn SHOW VARIABLES has big output, which of them can be meaning in this case ?

What is wrong?

My docker-compose.yml has rows :

version: '3.1'

services:

    web:

        build:
            context: ./web
            dockerfile: Dockerfile.yml

        environment:
            - APACHE_RUN_USER=www-data
        volumes:
            - ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
        ports:
            - 8081:80
        working_dir: ${APP_PTH_CONTAINER}

    db:
        image: mysql:5.6.41
        restart: always
        environment: 
            MYSQL_ROOT_PASSWORD: 1
        volumes:
            - ${DB_PATH_HOST}:/var/lib/mysql


    phpmyadmin:
        depends_on:
          - db
        image: phpmyadmin/phpmyadmin
        restart: always
        ports:
          - 8082:80
        environment:
          PMA_HOST: db
          MYSQL_ROOT_PASSWORD: 1


    composer:
        image: composer:1.8
        volumes:
            - ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
        working_dir: ${APP_PTH_CONTAINER}
        command: composer install --ignore-platform-reqs

Thanks!



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2VeAoBd
via IFTTT

Aucun commentaire:

Enregistrer un commentaire