我在我的应用程序中使用SQLite3,它需要PostgreSQL,但您仍然可以使用Heroku进行开发。由于Heroku强烈建议不要使用两个不同的数据库,因此我决定改用PostgreSQL进行开发。我安装了gem pg
,还去了PostgreSQL官方网站获取Windows installer,还更改了我的database.yml
。在安装过程中,它需要PostgreSQL的密码,所以我创建了一个。在尝试创建数据库时,为了通过:fe_sendauth: no password supplied
,我必须将pg_hba.conf
文件从使用md5
更改为trust
。
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 trust # was md5
# IPv6 local connections:
host all all ::1/128 trust # was md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#host replication postgres 127.0.0.1/32 trust
#host replication postgres ::1/128 trust
不过,在去掉它之后,我现在得到了:
$ rake db:create
(in C:/app)
FATAL: role "User" does not exist
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"utf8",
"database"=>"app_test", "pool"=>5, "username"=>nil, "password"=>nil}
我仍然有我的development.sqlite3
和text.sqlite3
,这会是问题所在吗?必须做些什么?
这是我的全部要点:https://gist.github.com/1522188
发布于 2011-12-27 06:44:25
添加一个用户名到你的database.yml
,也可以使用你的应用程序的名字(或者名字的一些变体)作为用户名,我将使用app_name
作为占位符:
development:
adapter: postgresql
encoding: utf8
database: app_development
pool: 5
username: app_name
password:
然后使用psql.exe
在PostgreSQL中创建用户(也称为“角色”
$ psql -d postgres
postgres=# create role app_name login createdb;
postgres=# \q
第一行在终端中,接下来的两行在psql
中。然后做你的rake db:create
。
User
用户可能是默认用户,但在PostgreSQL中用于其他目的的user
is already taken用户,因此如果您想使用User
作为用户名,则必须将其引起来以保留大小写:
postgres=# create role "User" login createdb;
无论如何,您最好为每个应用程序创建一个用户。
您也希望对database.yml
中的test
条目执行类似的操作。
发布于 2017-06-07 13:37:47
例如,如果您的计算机上有一个名为postgres的特定帐户/用户。
然后,执行此命令将提示您输入角色名称。
sudo -u postgres createuser --interactive
然后做
rake db:create
应该行得通!
https://stackoverflow.com/questions/8639424
复制相似问题