【问题标题】:I can not run php artisan migrate我无法运行 php artisan migrate
【发布时间】:2018-12-05 18:20:14
【问题描述】:

我正在尝试运行php artisan migrate 命令,但没有得到它。我收到此错误

SQLSTATE[42601]: 语法错误: 7 错误: """" 处或附近的零长度分隔标识符\n 第 1 行:将 search_path 设置为 ""\n ^ (SQL: select count(*) as aggregate from "categoria" where "deleted_at" is null and "categoria"."deleted_at" is null)。

我的班级迁移类别:

<?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');
    }
}

这个地方发生在我运行 php artisan migrate 命令时。在vagrant中,出现这个错误

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

我的设置是 Laravel 最新的宅基地

  • Laravel 5.5
  • Postgres 10.4

如果有任何帮助,我将不胜感激!

【问题讨论】:

  • 请发布代码,而不仅仅是一个错误。寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定问题或错误必要的最短代码 在问题本身中重现它。没有明确的问题陈述的问题对其他读者没有用处。见:How to create a Minimal, Complete, and Verifiable example.
  • 你使用的是什么版本的 Laravel?
  • 您确定您的数据库配置正确吗? (尤其是 Postgres 架构?)
  • @RossWilson 我改进了对问题的描述。
  • @MattGibson 是的,我愿意。我正在使用 dbeaver 并检查了架构是否已创建。

标签: php laravel postgresql vagrant artisan-migrate


【解决方案1】:

我能够通过将/vendor/laravel/framework/src/Illuminate/Database/Connectors/PostgresConnector.php 类的configureSchema ($connection, $config) 方法的$schema 变量更改为我创建的架构来解决我的问题。

之前

/**
 * 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();
    }
}

之后

/**
 * 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();
    }
}

我意识到调试堆栈跟踪的问题并意识到由于某种原因$schema 变量为空。

如果有人简洁地解释了为什么会发生此错误,我将其标记为答案。

【讨论】:

    猜你喜欢
    • 2016-09-07
    • 1970-01-01
    • 2017-08-08
    • 2019-02-24
    • 1970-01-01
    • 1970-01-01
    • 2020-07-16
    • 2021-06-06
    • 2017-05-31
    相关资源
    最近更新 更多