4

I'm trying to run the php artisan migrate command, but I'm not getting it. I'm getting this error

SQLSTATE[42601]: Syntax error: 7 ERROR: zero-length delimited identifier at or near """"\n LINE 1: set search_path to ""\n ^ (SQL: select count(*) as aggregate from "categoria" where "deleted_at" is null and "categoria"."deleted_at" is null).

My class migration Categoria:

<?php

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

class CreateCategoriasTable extends Migration
{
    /**
    * Run the migrations.
    *
    * @return void
    */
    public function up()
    {
        Schema::create('categoria', function (Blueprint $table) {
            $table->increments('id');
            $table->string('nome', 60);
            $table->timestamps();
            $table->softDeletes();
        });
    }

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

This place happens when I run the php artisan migrate command. In vagrant, this error appears

vagrant@homestead:~/code/controle-interno$ php artisan migrate
**************************************
*     Application In Production!     *
**************************************

 Do you really wish to run this command? (yes/no) [no]:
 > yes


In Connection.php line 664:

  SQLSTATE[42601]: Syntax error: 7 ERROR:  zero-length delimited identifier at or near """"
  LINE 1: set search_path to ""
                             ^ (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations)


In PDOStatement.php line 143:

  SQLSTATE[42601]: Syntax error: 7 ERROR:  zero-length delimited identifier at or near """"
  LINE 1: set search_path to ""
                             ^


In PDOStatement.php line 141:

  SQLSTATE[42601]: Syntax error: 7 ERROR:  zero-length delimited identifier at or near """"
  LINE 1: set search_path to ""
                             ^

My setup is Laravel's most current homestead

  • Laravel 5.5
  • Postgres 10.4

I will be very grateful for any help!

Iago Frota
  • 191
  • 1
  • 11
  • Please post code, not just an error. Questions seeking debugging help (“**why isn’t this code working?**”) must include the desired behavior, a *specific problem or error* and *the shortest code necessary* to reproduce it **in the question itself**. Questions without **a clear problem statement** are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example.](http://stackoverflow.com/help/mcve) – elixenide Jun 27 '18 at 00:34
  • What version of Laravel are you using? – Rwd Jun 27 '18 at 07:02
  • Are you sure your database configuration is correct? (Especially the Postgres schema?) – Matt Gibson Jun 27 '18 at 09:40
  • @RossWilson I improved the description of my problem. – Iago Frota Jun 28 '18 at 00:05
  • @MattGibson Yes, I do. I'm using dbeaver and checked that the schema was created. – Iago Frota Jun 28 '18 at 22:37

1 Answers1

0

I was able to solve my problem by changing the $schema variable of the configureSchema ($connection, $config) method of the /vendor/laravel/framework/src/Illuminate/Database/Connectors/PostgresConnector.php class to the schema I created.

Before

/**
 * Set the schema on the connection.
 *
 * @param  \PDO  $connection
 * @param  array  $config
 * @return void
 */
protected function configureSchema($connection, $config)
{
    if (isset($config['schema'])) {
        $schema = $this->formatSchema($config['schema']);

        $connection->prepare("set search_path to {$schema}")->execute();
    }
}

After

/**
 * Set the schema on the connection.
 *
 * @param  \PDO  $connection
 * @param  array  $config
 * @return void
 */
protected function configureSchema($connection, $config)
{
    if (isset($config['schema'])) {
        // $schema = $this->formatSchema($config['schema']);
        $schema = 'controle_interno';

        $connection->prepare("set search_path to {$schema}")->execute();
    }
}

I realized the problem debugging the stacktrace and realized that for some reason the $schema variable was coming empty.

If someone succinctly explains why this error is happening, I mark it as an answer.

Iago Frota
  • 191
  • 1
  • 11