简体   繁体   中英

PostgreSQL error when run migration Lumen/Laravel

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

Lumen doesn't come with a config/database.php file by default. You can either copy a default Laravel file, or create your own with your own settings.

If you've already added your own custom file, it looks like you need to specify the migrations table name.

Default entry for Laravel is 'migrations' => 'migrations' , but of course you can name it whatever you like.

I got the same problem on a Laravel 7.x project. My solution was to remove the cache of my application then to update my dependencies via composer:

php artisan cache:clear
composer update

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM