2012-07-04 18 views
4

我有一個Rails 3.2.1項目,我試圖運行我的規格。Rails 3,rake db:test:prepare在使用postgres Schema時不起作用

當我運行: 耙

rake aborted! PG::Error: ERROR: invalid value for parameter "search_path": "example" DETAIL: schema "example" does not exist : SET search_path TO example

從我可以工作了,耙分貝:測試:準備下降的測試數據庫,然後試圖從schema.rb重新創建它。事情是,database.yml有行

schema_search_path: example

所以當它試圖重新連接,它會失敗,並出現上述錯誤。

我想我的問題是,我怎麼能得到耙db:測試:準備設置schema_path呢?

回答

-1

你應該設定在你的配置中schema_search_path/database.yml中

例如

development: 
    adapter: postgresql 
    encoding: unicode 
    database: test 
    pool: 5 
    username: user 
    password: password 
    #host: localhost 
    #port: 5432 
    # Schema search path. The server defaults to $user,public 
    schema_search_path: example 
+0

護理爲什麼下來解釋投票我的答案? – number5

0

一種解決方法是向db:create任務添加一些代碼,創建該架構。把這個rake任務,爲〔實施例 'APP_ROOT/lib目錄/任務/ db_create_schema.rake'

namespace :db do 
    task :create do 
    config = Rails.configuration.database_configuration[Rails.env].merge!({'schema_search_path' => 'public'}) 
    ActiveRecord::Base.establish_connection(config) 
    ActiveRecord::Base.connection.execute("CREATE SCHEMA schema_name") 
    end 
end 

https://gist.github.com/4280172

相關問題