我正在尝试开始使用 PostgreSQL,但遇到了一些麻烦。
我为开发创建数据库并且它正在工作。我已经创建了表格并添加了一些对象。我按照这篇文章创建数据库 - http://blog.deliciousrobots.com/2011/12/13/get-postgres-working-on-ubuntu-or-linux-mint/
这是代码,我运行以创建 test_database
denmed@denmed:~/projects/internet_shop$ sudo -u postgres createdb -O denys internet_shop_test
denmed@denmed:~/projects/internet_shop$ psql -d internet_shop_test -U denys -WPassword for user denys:
denmed@denmed:~/projects/internet_shop$ psql -d internet_shop_test -U denys -W
Password for user denys:
psql (9.1.7)
Type "help" for help.
internet_shop_test=>
这意味着我创建了数据库并且可以使用它吗?
然后,在另一个控制台(当我在另一个控制台中登录测试数据库时)我运行命令
rake test
并得到这个错误(我会剪掉它):
Errors running test:units! #<ActiveRecord::StatementInvalid: PG::Error: ERROR:
database "internet_shop_test" is being accessed by other users
DETAIL: There are 1 other session(s) using the database.
: DROP DATABASE IF EXISTS "internet_shop_test">
Errors running test:functionals! #<RuntimeError: Command failed with status (1): [ruby
-I"lib:test" -I"/home/denmed/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.0.3/lib" "/home
/denmed/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.0.3/lib/rake/rake_test_loader.rb"
"test/functional/**/*_test.rb" ]>
好的,它告诉我我正在访问数据库。然后我关闭登录的测试数据库终端并再次运行 rake test 并得到这个:
PG::Error: ERROR: permission denied to create database
...
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode",
"database"=>"internet_shop_test", "pool"=>5, "username"=>"denys",
"password"=>"********"}
...
PG::Error: FATAL: database "internet_shop_test" does not exist
这是我用于开发和测试数据库的 database.yml:
development:
adapter: postgresql
encoding: unicode
database: internet_shop_development
pool: 5
username: denys
password: ********
test:
adapter: postgresql
encoding: unicode
database: internet_shop_test
pool: 5
username: denys
password: ********
我做错了什么?