Laravel 5.8, MySQL5.6のDockerfileでマイグレーションしたら、えっらー!
$ docker-compose exec php-fpm php /app/artisan migrate:refresh Migration table not found. Migration table created successfully. Migrating: 2014_10_12_000000_create_users_table 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 `users` add unique `users_email_unique`(`email`)) at /app/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| }
Laravel5.4以上かつMySQL5.7.7未満でmigrationすると「Specified key was too long; max key length is 767 bytes (SQL: alter table `users` add unique・・・」エラーが出る。
解決策
MySQLのバージョンを上げる
docker-compose.yml
$ cat docker-compose.yml version: '3.2' services: mysql57: container_name: "mysql56" image: mysql:5.7 environment: MYSQL_DATABASE: yomuyodb MYSQL_ROOT_PASSWORD: naishodayo ports: - "3306" restart: always volumes: - "../db:/var/lib/mysql" nginx: container_name: "nginx" build: context: . dockerfile: ./docker/nginx/Dockerfile volumes: - "./yomuyo/public:/app/public/" ports: - "80:80" depends_on: - php-fpm restart: always php-fpm: container_name: "php-fpm" build: context: . dockerfile: ./docker/php-fpm/Dockerfile volumes: - "./yomuyo/:/app/" restart: always links: - mysql57 pma: container_name: "pma" image: phpmyadmin/phpmyadmin:latest environment: PMA_HOST: mysql57 ports: - "8080:80" restart: always links: - mysql57
MySQLのイメージをmydql5.6からmysql5.7に変更することで対応
PHP-FPMのDockerfile
FROM php:7-fpm ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && apt-get install -y git zlib1g-dev zip unzip libzip-dev RUN docker-php-ext-install zip mysqli pdo_mysql RUN mkdir -p /app ADD ./ /app WORKDIR /app RUN usermod -u 1000 www-data RUN groupmod -g 1000 www-data RUN chown -R www-data:www-data /app # install composer ENV COMPOSER_ALLOW_SUPERUSER 1 ENV COMPOSER_HOME /composer ENV PATH $PATH:/composer/vendor/bin RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
pdo_mysql, mysqliも必要なので、「RUN docker-php-ext-install zip mysqli pdo_mysql」をしよう。
@see