ucan-lab / docker-laravel

🐳 Build a simple laravel development environment with Docker Compose.
https://dev.to/ucan_lab/how-to-install-and-set-up-laravel-s-local-development-environment-with-docker-compose-5bcf
MIT License
1.17k stars 380 forks source link

Migration mysql driver error #225

Closed Ambroz91 closed 1 year ago

Ambroz91 commented 1 year ago

Hey. I'm having troble with an migration in docker. It sqys that there is a missing driver for mysql. Please help me with this.

First Error: php artisan migrate

Illuminate\Database\QueryException

could not find driver (Connection: mysql, SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')

at vendor\laravel\framework\src\Illuminate\Database\Connection.php:793 789▕ // If an exception occurs when attempting to run a query, we'll format the error 790▕ // message to include the bindings with SQL, which will make this exception a 791▕ // lot more helpful to the developer instead of just the database's errors. 792▕ catch (Exception $e) { ➜ 793▕ throw new QueryException( 794▕ $this->getName(), $query, $this->prepareBindings($bindings), $e

Second Error docker compose exec app php artisan migrate

Illuminate\Database\QueryException

SQLSTATE[HY000] [2002] Connection refused (Connection: mysql, SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')

at vendor/laravel/framework/src/Illuminate/Database/Connection.php:793
789▕ // If an exception occurs when attempting to run a query, we'll format the error 790▕ // message to include the bindings with SQL, which will make this exception a
791▕ // lot more helpful to the developer instead of just the database's errors.
792▕ catch (Exception $e) {
➜ 793▕ throw new QueryException(
794▕ $this->getName(), $query, $this->prepareBindings($bindings), $e
795▕ );
796▕ }
797▕ }

  +38 vendor frames                                                                                                                                      

39 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

ucan-lab commented 1 year ago

@Ambroz91 Sorry for the late reply...🙏

could not find driver (Connection: mysql, SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')

This is an error when the pdo_mysql extension is not present. The pdo_mysql extension module is installed at this time.

https://github.com/ucan-lab/docker-laravel/blob/main/infra/docker/php/Dockerfile#L31

This error probably occurred because php on the host OS was executed, not inside a Docker container. This error should not occur if you use the php command inside the container with the command below.

docker compose exec app php artisan migrate
ucan-lab commented 1 year ago

As time has passed, this issue will be closed. Please re-open if you have any problems.