Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

iagofrota's avatar

I can not run php artisan migrate

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).

I'm using the PostgreSQL database to post my migrations and I'm running my application on vagrant.. I will be very grateful for any help!

0 likes
10 replies
akLearn's avatar

Try to run "php artisan " alone. If you get the same error, then there's probably a command (App\Console\Commands) which was created on this project and has an error in it.

You can do search the whole project using some of the keywords above and see if that helps.

SANTI1111's avatar

try to put parameters to the columns in the table also if they are nullable

mattsplat's avatar

Look at the migration that references "categoria".

iagofrota's avatar

@mattsplat This is the migration to 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');
    }
}
iagofrota's avatar

@mattsplat 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 ""
                             ^

and when I go to the page, I get this error

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

iagofrota's avatar
iagofrota
OP
Best Answer
Level 1

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.

Please or to participate in this conversation.