1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

laravelでmigrationが通らなかった時に対応したこと(Illuminate\Database\QueryException )

Last updated at Posted at 2022-04-19

エラーの背景

以下のようなエラーが出ました。

$ php artisan migrate
Illuminate\Database\QueryException 

  SQLSTATE[HY000] [1049] Unknown database 'laravel-todo_db' (SQL: select * from information_schema.tables where table_schema = laravel-todo_db and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:745
    741▕         // If an exception occurs when attempting to run a query, we'll format the error
    742▕         // message to include the bindings with SQL, which will make this exception a
    743▕         // lot more helpful to the developer instead of just the database's errors.
    744▕         catch (Exception $e) {
  ➜ 745▕             throw new QueryException(
    746▕                 $query, $this->prepareBindings($bindings), $e
    747▕             );
    748▕         }
    749▕     }

      +33 vendor frames 
  34  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

mysqlが接続されていないことが原因でした。

有益な記事

基本mysql接続はこの記事で接続ができてエラーが解決しました。
https://yaba-blog.com/laravel-db/

このエラーが出たらこの記事も参考にする

MySQL Workbenchを入れておく

phpadminは基本実務で使わないので、MySQL Workbenchをダウンロードします。

上の方法以外で解決した方法

.example.env
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laraveldb
DB_USERNAME=dbuser
.example.env
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost8080

LOG_CHANNEL=stack

DB_CONNECTION=laravel_db
DB_HOST=laravel_db
DB_PORT=3306
DB_DATABASE=laraveldb
DB_USERNAME=dbuser

に修正したら、解決して、Adminerに入ることができて、マイグレーションも通りました。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?