MAMP環境で開発していたLaravelプロジェクトをAWSにデプロイする際に、
EC2上で php artisan migrateを実行するとエラーが発生するので解決したい
状況としてはLaravelプロジェクトはブラウザで表示されている。
エラー表示
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = and table_name = migrations and table_type = 'BASE TABLE') at /var/www/html/namilog/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: 1 PDOException::("SQLSTATE[HY000] [2002] No such file or directory") /var/www/html/namilog/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70 2 PDO::__construct("mysql:unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock;dbname=", "namilog", "password", []) /var/www/html/namilog/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70 Please use the argument -v to see more details.
と表示され実行できません。
unix_socketあたりが問題なのでしょうか?
.envは以下で設定しています。
env
1DB_CONNECTION=mysql 2DB_HOST=<エンドポイント> 3DB_PORT=3306 4DB_DATABASE= 5DB_USERNAME=<マスターユーザー名> 6DB_PASSWORD=<パスワード>
マイグレーション対象ファイルは以下です。
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateUsersTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->integer('stance')->default(1); $table->integer('board')->default(1); $table->string('introduction')->nullable(); $table->string('image_path')->nullable(); $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); $table->rememberToken(); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('users'); } }
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateSpotsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('spots', function (Blueprint $table) { $table->increments('id'); $table->integer('user_id')->unsigned(); $table->string('name'); $table->string('place'); $table->string('body'); $table->timestamps(); // 外部キーを設定する $table->foreign('user_id')->references('id')->on('users'); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('spots'); } }
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateDiariesTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('diaries', function (Blueprint $table) { $table->increments('id'); $table->integer('spot_id')->unsigned(); $table->integer('user_id')->unsigned(); $table->string('title'); $table->integer('score'); $table->integer('condition'); $table->integer('size'); $table->string('body'); $table->string('image_path')->nullable(); $table->timestamps(); // 外部キー設定 $table->foreign('spot_id')->references('id')->on('spots'); $table->foreign('user_id')->references('id')->on('users'); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('diaries'); } }
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateCommentsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('comments', function (Blueprint $table) { $table->increments('id'); $table->integer('user_id')->unsigned(); $table->integer('diary_id')->unsigned(); $table->string('body'); $table->timestamps(); //外部キー $table->foreign('user_id')->references('id')->on('users'); $table->foreign('diary_id')->references('id')->on('diaries'); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('comments'); } }
回答4件
あなたの回答
tips
プレビュー