问题描述
我在Debian 7下将Rails 4.1.5与Postgresql 9.1一起使用,但无法在开发环境中创建数据库。当我运行
I'm using rails 4.1.5 with postgresql 9.1 under Debian 7, and I'm not able to create a database in my development environment. When I run
bin/rake db:create
我得到
home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:898:in `rescue in connect': FATAL: database "direct-dev" does not exist
Run `$ bin/rake db:create db:migrate` to create your database (ActiveRecord::NoDatabaseError)
from /home/rs/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
from ...
我试图创建数据库,所以自然不存在。但是rails应该创建它...这是我的config / database.yml:
I am trying to create the database so, naturally, it does not exist. However rails should create it ... Here's my config/database.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: direct-dev
这是postgresql日志的一部分:
And here's a part of the postgresql log:
2014-09-01 19:30:40 CEST LOG: connection received: host=[local]
2014-09-01 19:30:40 CEST LOG: connection authorized: user=rs database=direct-dev
2014-09-01 19:30:40 CEST FATAL: database "direct-dev" does not exist
您有指针吗?我已经在这里待了一个多小时,但仍然不明白为什么会这样...
Do you have any pointers? I've been at this for more than an hour, and still can't understand why this is happening ...
谢谢!
推荐答案
Rails 4.1 和
Rails 4.1 ships with spring preloader, and
这意味着弹簧化 bin / rake
将尝试预加载该应用程序,而该应用程序又将尝试运行初始化程序,从而导致您遇到的问题。
which means that the "springified" bin/rake
will attempt to preload the app, which in turn will attempt to run the initilizers resulting in the problem you're seeing.
要解决/解决此问题,您需要在没有弹簧的情况下运行初始设置耙任务。实现此目标的一种方法是使用捆绑程序运行它:
To fix / work around this you want to run the initial setup rake tasks without spring. One way to achieve that is to run it with bundler instead:
bundle exec rake db:create
这篇关于rake db:create抛出“数据库不存在” PostgreSQL错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!