Shou9
@Shou9

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

PHP 掲示板作成 質問

PHPの掲示板作成について

PHPのlaravel、MAMPの環境で動画を参考に掲示板を作成しています。

動画    https://youtu.be/5U0p_OjMmYc

そして、データベースを作るためにphp artisan migrateのコマンドを打ったのですが画像のようなエラーが起きてしまいます。
解決方法を教えて下さい。

発生している問題・エラー

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

  at /Applications/MAMP/htdocs/laravel/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:

自分で試したこと

.envのファイルでDBの名前を変えてみたり、database.phpのファイルでの名前の変更などしてみました。

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=8889
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=root

0

2Answer

エラー内容にDBが存在しませんとなっていますが、
DB名はlaravelでお間違いないでしょうか?

0Like

Comments

  1. @Shou9

    Questioner

    DB名の書いてある場所が分かりませんが、間違いないと思います。

Unknown database 'laravel'

おそらく「laravel」という名前のデータベースが無いのだと思います。

動画だと「development」というデータベースにしているので、このあたり(10:54)の作業が漏れているのではないでしょうか?

0Like

Comments

  1. @Shou9

    Questioner

    (10:54)の作業を行なったのですが、DB_DATABASEの名前をdevelopmentとすれば解決しますか?一度試したのですが改善しなくて..。この動画では行なっていませんが、データベースをmysqlとかで作成しなければいけませんか?
  2. > この動画では行なっていませんが、データベースをmysqlとかで作成しなければいけませんか?

    はい。作成する必要があります。

    動画ではDocker環境で構築されており、その過程でdevelopmentデータベースが作成されているようです。
    動画とは違う環境でやっているのでしたら、ご自身の環境に合わせて前提条件を整える必要があります。

Your answer might help someone💌