我的应用程序使用Heroku,它需要PostgreSQL,但您仍然可以使用SQLite3进行开发.由于Heroku强烈建议不要使用两个不同的数据库,我决定改用PostgreSQL进行开发.我安装了gem pg,还go 了PostgreSQL官方网站获取Windows安装程序,还更改了我的database.yml.在安装过程中,它需要PostgreSQL的密码,所以我做了一个.

# 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.sqlite3text.sqlite3礼物,这是问题吗?必须做什么?

以下是我的全部要点:https://gist.github.com/1522188

推荐答案

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;

不管怎样,最好还是 for each 应用程序创建一个用户.

database.yml中,你也会想为你的test个条目做类似的事情.

Ruby-on-rails相关问答推荐

rails中Net::STP的多文件模式

`heroku Open`和`heroku run rake db:Migrate`不工作(";没有这样的文件或目录";)

Gemfile需要较新版本的依赖项

如何断言 Ruby 单元测试中的错误消息?

如何让删除链接响应 Rails 7 中的 turbo_stream 和 html?

如何获取 Rails 表单构建器将为某个字段生成的 HTML名称属性?

使用带有 bootstrap-sass gem 的 Rails 4 无法让 CSS 在 Heroku 上工作

Rails 4 Form: has_many through: checkboxes

RSpec 设置会话对象

使用 javascript 提交 Rails 远程表单

OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=SSLv3 read server hello A

具有条件的列的计数器缓存?

Ruby 元素是否存在于数组中

如何在where子句中组合两个条件?

如何在 RoR 中实现成就系统

过滤器在渲染之前但在控制器之后执行?

Rails 3.1 中的 Rails.cache 错误 - TypeError: can't dump hash with default proc

用于在多行上链接调用的 Ruby 约定

Sidekiq Rails 4.2 使用 Active Job 还是 Worker?有什么不同

在 Rails 3 中突出显示当前页面的最佳方法? -- 有条件地将css类应用于链接