php – PostgreSQL error when run migration Lumen/Laravel-ThrowExceptions

Exception or error:

I recently changed the way my application connects to my PostgreSQL database to add the read/write principle. Since then, when I launch a migration I get the following error:

In Connection.php line 463:

  [PDOException (42601)]                                                                     
  SQLSTATE[42601]: Syntax error: 7 ERROR:  zero-length delimited identifier at or near """"  
  LINE 1: create table "" ("id" serial primary key not null, "migratio...                    
                       ^

when I delete the database.php file, my migrations work correctly.

My .env

DB_CONNECTION=pgsql
DB_HOST=192.168.1.1
DB_PORT=5432
DB_DATABASE=database
DB_USERNAME=user
DB_PASSWORD=password

DB_USERNAME_READ=user
DB_PASSWORD_READ=password

My database.php

<?php

return [

    'default' => env('DB_CONNECTION', 'pgsql'),

    'connections' => [
        'pgsql' => [
            'read' => [
                'username'  => env('DB_USERNAME_READ'),
                'password'  => env('DB_PASSWORD_READ'),
            ],
            'write' => [
                'username'  => env('DB_USERNAME'),
                'password'  => env('DB_PASSWORD'),
            ],
            'sticky'    => true,
            'driver'    => 'pgsql',
            'host'      => env('DB_HOST'),
            'database'  => env('DB_DATABASE'),
        ],
    ],
];

and one of my migrations:

<?php

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

class CreateGameUserTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('game_user', function (Blueprint $table) {
            $table->bigInteger('game_id');
            $table->bigInteger('user_id');
            $table->foreign('game_id')->references('id')->on('games');
            $table->foreign('user_id')->references('id')->on('users');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('game_user');
    }
}
  • PHP 7.3.13
  • Lumen 6.3.3
  • PostegreSQL 9.6.2
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *