我使用Heroku作为我的应用程序,它需要PostgreSQL,但是仍然可以使用SQLite 3进行开发。由于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
向你的database.yml
,不如使用应用程序的名称(或名称的某些变体)作为用户名,我将使用app_name
作为占位符:
development: adapter: postgresql encoding: utf8 database: app_development pool: 5 username: app_name password:
然后使用以下方法在PostgreSQL中创建用户(AKA“角色”)psql.exe
:
$ psql -d postgres postgres=# create role app_name login createdb; postgres=# \q
第一行在终端,下两行在终端内。psql
...。那就做你的rake db:create
...
User
用户可能是默认的,但是user
已经被用于PostgreSQL中的其他用途,因此,如果想要使用,则必须引用它以保留情况。User
作为用户名:
postgres=# create role "User" login createdb;
无论如何,你最好为每个应用程序创建一个用户。
你会想为你的孩子做类似的事test
进入database.yml
也一样。
如果username
在你的config/database.yml
。在OSX和Linux上,你能看到这是和谁在一起吗?whoami
...。看来你在用Windows。
解决方案A:创建PostgreSQL用户和它要找的那个相符。例如
createuser --superuser some_user
解决方案B:通过显式设置用户名更改DB用户