我在使用Heroku来构建我的应用程序,需要使用PostgreSQL数据库,但仍然可以在开发时使用SQLite3。由于Heroku强烈反对在同一应用程序中使用两种不同的数据库,因此我决定将开发环境改为使用PostgreSQL。我安装了gem pg
,并访问了官方的PostgreSQL网站以获取Windows安装程序,并更改了database.yml
文件。在安装过程中,需要设置一个PostgreSQL密码,因此我设置了一个密码。
我不得不将pg_hba.conf
文件从使用md5
更改为trust
,以便在尝试创建数据库时避免出现fe_sendauth: no password supplied
错误。
# 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
psql.exe
。当我尝试打开它时,窗口会弹出然后自动关闭,所以我尝试去命令提示符并输入c:\Program Files..\..\bin > psql.exe > psql: FATAL: role "User" does not exist
再次得到FATAL
。有什么想法吗? - LearningRoRpostgres
用户,对吧?如果需要密码,则尝试psql -d postgres -U postgres -W
。如果不需要密码,则使用psql -d postgres -U postgres
。 - mu is too shortpsql -d postgres -U postgres
吗? - mu is too shortcreate role app_name login createdb
或alter role app_name createdb
,然后再运行rake db:create
。我上次执行此操作时可能设置了不同的默认值。 - mu is too shortpsql
中使用\du
命令查看用户/角色及其权限,或使用\l
命令列出数据库。如果您的用户设置正确,则rake db:create
命令应该会创建数据库,而psql -U app_name -d app_development
命令则可进入该数据库。 - mu is too short