1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ローカル開発環境でLaravelのmigrateができない場合の解決方法

Last updated at Posted at 2020-07-22

php artisan migrateが実行できない場合の解決方法

##環境
MacBookPro 2020
Homebrew  2.4.8
MySQL     Ver 8.0.21 for osx10.15 on x86_64 (Homebrew)
PHP     7.3.11 (cli) (built: Jul 5 2020 03:23:39) ( NTS )

##原因
configのキャッシュが残っている
MySQLのversionが8.0以降の場合、envファイルへの追記が必要。
##解決方法
下記コマンドでconfigのキャッシュを消去後、再度migrate実行

php artisan config:clear

#別のエラーが出ている場合 エラーコード

 Illuminate\Database\QueryException  : SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = laravel-course and table_name = migrations and table_type = 'BASE TABLE')

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

  Exception trace:

  1   PDOException::("SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)")
      /Applications/MAMP/htdocs/laravel-course/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

  2   PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=laravel-course", "root", "root", [])
      /Applications/MAMP/htdocs/laravel-course/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

  Please use the argument -v to see more details. 

##エラー解決方法
1 MySQLに'データベース'を作成
2 作業用ユーザーの作成
3 env .database.phpの情報を合わせる

.envの情報を以下にする
DB_CONNECTION=mysql
DB_HOST=localhost
DB_DATABASE='データベース'
DB_USERNAME=root
DB_PASSWORD=root
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock

4 

clear

php artisan migrate
で完了

1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?