gpt4 book ai didi

php - 我无法运行 php artisan migrate

转载 作者:搜寻专家 更新时间:2023-10-31 21:48:14 27 4
gpt4 key购买 nike

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

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

我的类(class)迁移分类:

<?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 最新的 homestead

  • Laravel 5.5
  • Postgres 10.4

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

最佳答案

我能够通过更改 /vendor/laravel 的 configureSchema ($connection, $config) 方法的 $schema 变量来解决我的问题/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 变量变空了。

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

关于php - 我无法运行 php artisan migrate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51052864/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com