开发者

Problem with rake: "development database is not configured"

开发者 https://www.devze.com 2023-03-22 16:23 出处:网络
I am novice rails/terminal user and just did a clean install of Lion + Xcode + Rails. Unlike before (on Snow Leopard), I now get an error running rake db:migrate.

I am novice rails/terminal user and just did a clean install of Lion + Xcode + Rails. Unlike before (on Snow Leopard), I now get an error running rake db:migrate.

I have cloned my code through git which worked fine and created the database witht the "createdb" command but when I try run "rake db:migrate" in terminal it now comes up with this error:

rake aborted!
development database is not configured

My config/database.yml file looks like below in the development section which is exactly the way it looked before on Snow Leopard where it worked fine, so don't know if the error I am now getting is related to Lion.

development:  
adapter: postgresql
database: my_db
username: rasmus
encoding: utf8
pool: 5
开发者_如何学Python

Can anyone help, please?


I got the same error and in my case it was because the database.yml was not indented correctly. All the configuration parameters should be indented.


Note, be sure to follow the proper spacing conventions. The database config is whitespace aware. Two spaces per attribute works fine. In the following code, note how each attribute has two spaces. Do not use tabs. If you don't use spaces for attributes, rake will not work and throw the same error.

development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: postgresql
  encoding: unicode
  database: db/production
  pool: 5
  timeout: 5000
  password:


You might also want to look for syntax errors in the file. This is the error that will appear if you have a syntax error in your config/database.yml file and you try to do something like start the local web server or run rake db:migrate.

In my case I had accidentally removed the comment from a line at the top of the file and I was seeing this error since the uncommented line made this an invalid yml file.


Solved!

My "gem install pg" had not been run so basically I was missing the pg gem. After "gem install pg" in terminal everything works fine.


Here's a PEBCAK answer for Googlers - check your Gemfile and make sure you have specified your database adapter gem in the proper group in your Gemfile. I had mine defined for only :production and :staging, and at one point must have manually ran gem install pg on my development machine after switching from mysql. This morning I emptied all of the gems for the app and re-bundle install-ed them, then couldn't figure out why the database wouldn't connect. Moving the pg gem spec outside of any group and running bundle install resolved the problem.


A note to others who land on this question page: be sure that you are running the rake db command correctly, i.e:

rake db:migrate instead of rake db migrate


What worked in my case, having tried all the above when rake db:create failed, was to make sure that my Rakefile was properly configured.

This did the job:

require "sinatra/activerecord/rake"
require 'sinatra/asset_pipeline/task'

namespace :db do
  task :load_config do
    require "./app"
  end
end
0

精彩评论

暂无评论...
验证码 换一张
取 消