0
votes

I am trying to do a migration in Laravel but get the following error:

Illuminate\Database\QueryException SQLSTATE[HY000] [2002] No such file or directory

I am using postgresql as my database. I changed DB_CONNECTION=pgsql and DB_PORT=5432 but I am still getting an error. Is there an issue with my migration? I am trying to make an Item model.

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateItemsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
      Schema::create('items', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->boolean('completed')->default(false);
            $table->timestamp('completed_at')->nullable();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('items');
    }
}

Here is the entire database from my .env file:

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:FhYiDxPAuoIoIA3cP/aDNn7xvoRf/rhcyoLtr4EZB+4=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=postgres
DB_USERNAME=admin
DB_PASSWORD=123456

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
1
Usually that message is because you are connecting to the database using a socket file and that file does not exist. Can you share the rest of your database configuration?apokryfos
Try with DB_HOST=127.0.0.1 instead of DB_HOST=localhost Also don't forget to refresh caches after that change: php artisan config:cacheboolfalse
By default it was 127.0.0.1. I tried the config:cache command but still get the same error.SJK

1 Answers

0
votes
php artisan config:clear

then you can migrate your database

php artisan migrate:install