【发布时间】:2015-03-22 21:45:36
【问题描述】:
我正在尝试创建用于开发和测试的 postgres 数据库。我正在使用:
- OSX 优胜美地
- Rails 版本:4.2.0
- git 版本:2.2.2
- psql 版本:9.4.0
- 红宝石版本:2.1.0p0
- 自制版本:0.9.5
宝石文件:
gem 'pg'
数据库.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: myapp_development
username: username
password:
test:
<<: *default
database: myapp_test
rake db:create:all 返回
PG::InsufficientPrivilege: ERROR: permission denied to create database
: CREATE DATABASE "myapp_development" ENCODING = 'unicode'
.... (lots of tracing)
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "database"=>"myapp_development", "username"=>"username", "password"=>nil}
myapp_test already exists
怎么了?
编辑
我刚刚尝试将 database.yml 中的用户名更改为我在 Mac 上使用的用户名。有效。它还告诉我不仅maybe_test 已经存在,而且它还告诉我myapp_development 也已经存在。
- 为什么它不能使用我创建并分配给
CREATEDB角色的另一个用户名? - 为什么说开发无法创建然后告诉我它已经存在?
这一切看起来都太令人困惑了,让我想起了过去用 Apache 进行 PHP 设置。我不想每次创建新应用时都要处理问题,并尝试遵循 Heroku 的建议,在开发过程中也使用 PostgreSQL。
【问题讨论】:
-
rake db:drop:all然后rake db:create:all -
关注this answer 以提供您使用的
CREATEDB角色。你的问题将得到解决。并执行rake db:drop和rake db:create。
标签: ruby-on-rails ruby postgresql