gpt4 book ai didi

php - Laravel 迁移和 PostgreSQL 架构

转载 作者:行者123 更新时间:2023-12-02 21:24:51 26 4
gpt4 key购买 nike

我正在使用 PostgreSQL 并想尝试 Laravel。

首先 - 我的 up() 函数:

public function up()
{
Schema::create('entries.entries', function($t) {

$t->increments('id');
$t->string('username', 50);
$t->string('email', 100);
$t->text('comment');
$t->timestamps();
});
}

我有两个问题:

1) 我的数据库中没有 shema 条目,那么,我怎样才能更改我的 up 函数来创建它呢?我不想手动执行此操作。

2) 执行迁移时出现错误:

 sudo php artisan migrate

[Illuminate\Database\QueryException]
SQLSTATE[3F000]: Invalid schema name: 7 ERROR: no schema has been selected
to create in (SQL: create table "emigrations" ("migration" varchar(255) not null,
"batch" integer not null))

我该如何解决?

最佳答案

好吧,我知道这个问题已经有 2 年多的时间了……但对于 future 的人来说,达到这个目的。默认情况下,Laravel 不识别 postgres 的默认“公共(public)”模式,这就是为什么你得到:

[照亮\数据库\查询异常]
SQLSTATE[3F000]:无效的模式名称:7 错误:未选择任何模式
在 (SQL: create table "emigrations"("migration"varchar(255) not null, “批处理”整数不为空))

因此,为了解决这个错误,您只需将 postgres 中的 Schema 重命名为 public 以外的任何名称,并且在文件 config/database.php 的 laravel 项目中,将 pgsql 连接模式的名称更改为您想要在您的数据库。

这应该可以解决。

无论如何它对我有用......

关于php - Laravel 迁移和 PostgreSQL 架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25222119/

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