Laravel 迁移和 PostgreSQL 模式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25222119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel migration and PostgreSQL schemas
提问by fiction
I'm using PostgreSQLand want to try Laravel.
我正在使用PostgreSQL并想尝试 Laravel。
First - my up()
function:
首先 - 我的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();
});
}
And i have two questions:
我有两个问题:
1)I haven't shema entries
in my database, so, how can i change my up function to create it too? I dont want to do it manually.
1)entries
我的数据库中没有 shema ,所以,我如何更改我的 up 函数来创建它?我不想手动完成。
2)I got an error when executed migration:
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))
How can i fix it?
我该如何解决?
回答by jfalcon
1) I don't think there is such functionality in Laravel but you can use an external package like https://github.com/pacuna/Laravel-PGSchema
1)我认为 Laravel 中没有这样的功能,但您可以使用像https://github.com/pacuna/Laravel-PGSchema这样的外部包
2) Did you remove the default schema in your app/config/database.php file?
2)您是否删除了 app/config/database.php 文件中的默认架构?
'pgsql' => array(
'driver' => 'pgsql',
'host' => 'localhost',
'database' => 'forge',
'username' => 'forge',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
),
回答by Mauricio Jose Albanese Domingu
Well i know that this question has more than 2 year's... but for the future people that reaches this. Laravel does not recognize the default 'public' schema of postgres by default and that's why you get the:
好吧,我知道这个问题有超过 2 年的时间……但对于达到这一点的未来人来说。默认情况下,Laravel 无法识别 postgres 的默认“公共”模式,这就是为什么您会得到:
[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))
[Illuminate\Database\QueryException]
SQLSTATE[3F000]: Invalid schema name: 7 ERROR: no schema has been selected
in (SQL: create table "eigrations" ("migration" varchar(255) not null, "batch" integer)不为空))
Thus to solve this error you just rename your Schema in postgres to anything besides public and, in your laravel project in the file config/database.php change the name of your pgsql conection schema to the one you want to use in your DB.
因此,要解决此错误,您只需将 postgres 中的 Schema 重命名为 public 之外的任何名称,并且在文件 config/database.php 中的 Laravel 项目中,将 pgsql 连接模式的名称更改为要在数据库中使用的名称。
This should solve it.
这应该解决它。
It did for me anyways...
反正它对我有用...