我无法运行php artisan migration

时间:2018-06-27 00:06:24

标签: php laravel postgresql vagrant artisan-migrate

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

  

SQLSTATE [42601]:语法错误:7错误:在“”“” \ n或附近的零长度分隔标识符   第1行:将search_path设置为“” \ n                              ^(SQL:从“ categoria”中选择count(*)作为聚合,其中“ deleted_at”为空,“ categoria”。“ deleted_at”为空)。

我的班级迁移类别:

<?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@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

我将非常感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我能够通过将$schema类的configureSchema ($connection, $config)方法的/vendor/laravel/framework/src/Illuminate/Database/Connectors/PostgresConnector.php方法的/** * 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

我意识到调试堆栈跟踪的问题,并意识到由于某种原因column1: 1.pencil 2.color 3.brush column2: 1.ball 2.bat 3.wickets 4.field 5.players 6.coach 7.audience 变量为空。

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