2012-08-02 93 views
1

當前正在使用rails項目。當我試圖啓動rails服務器拋出以下錯誤:Ruby on Rails - 錯誤正在運行的服務器

=> Booting WEBrick 
=> Rails 3.1.3 application starting in development on http://0.0.0.0:3000 
=> Call with -d to detach 
=> Ctrl-C to shutdown server 
Exiting 
/var/lib/gems/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters  
/sqlite_adapter.rb:439:in `table_structure': Could not find table 'dbrick' 
(ActiveRecord::StatementInvalid) 

我的表名是'dbrick'。我也試圖耙db:drop和rake db:mirgrate。雖然遷移其拋出以下錯誤:

rake aborted! 
Could not find table 'dbrick' 

Tasks: TOP => db:migrate => environment 
(See full trace by running task with --trace) 

這是我的遷移文件:

class CreateDbricks < ActiveRecord::Migration 
def self.up 
    create_table :dbricks do |t| 
    t.text :description 
    t.string :video 
    t.string :video_html 
    t.string :image_id 
    t.string :option_id 
    t.boolean :choice 
    t.string :reach 
    t.integer :category_id 
    t.string :user_id 
    t.datetime :deleted_at 

    t.timestamps 
    end 
end 

def self.down 
    drop_table :dbricks 
end 
end 

這將是這麼多的幫助充滿如果任何人幫我出這一點。 在此先感謝。

+0

嘗試'rake db:schema:load'? – Trip 2012-08-02 10:23:54

+0

你有一個錯字:遷移創建'dbricks',但代碼嘗試使用'dbrick'表。 (複數與單數形式) – 2012-08-02 13:09:40

+0

感謝您的回覆。雅我試過耙db:架構:加載,但它給出了相同的錯誤,即耙中止! 找不到表「dbrick」 任務:TOP =>分貝:遷移=>環境 (請參閱通過運行帶有--trace任務全部跟蹤) – Abhiram 2012-08-02 15:02:40

回答

0

我會嘗試:

rake db:schema:load 

要加載的架構(而我相信它的發現對你的數據庫的錯誤)。

如果失敗了,我會手動查找創建您的dbrick遷移,找到該文件的名稱和文件名複製和粘貼的數目,以產生這樣的:

rake db:migrate:down VERSION=123412341234 # <-- where the number is the number you pasted 

查找錯誤。偶爾有一件事已經存在,或者已經不存在,並且阻止遷移一直運行,並且相應地,這將成爲你的錯誤的根源。如果這樣下去,然後成功耙它備份:

rake db:migrate:up VERSION=123412341234 # <-- where the number is the number you pasted 

如果它沒有成功去,那麼你就必須把你的礦工頭盔上,並讓你的手髒:

rails dbconsole 

這將帶你到你的數據庫,你將不得不手動刪除任何表/列阻止發生遷移。一旦修復,退出並且rake db:migrate:up

+0

非常感謝..得到它..你的答案幫助了我很多..謝謝 – Abhiram 2012-08-03 11:29:06

+0

太棒了!解決方案是什麼?如果它值得的話,不要忘記放棄並且設置一個正確的答案。 – Trip 2012-08-03 11:32:57

+0

我只是做耙分貝:遷移下來和分貝:遷移了..它的工作非常感謝 – Abhiram 2012-09-05 07:43:17

0

您是否已經遷移了數據庫? rake db:migrate

如果你有,放下你的數據庫(這將刪除所有數據,所以一定要小心 - 做到這一點,如果你不關心你的數據庫丟失數據)

rake db:drop 

這將清除出你的數據庫,和你的模式。然後

rake db:migrate 

這將重新遷移您的模式。

+0

感謝您的答覆..雅我放棄和遷移,因爲你說..放棄已完成,但同時遷移正在創造錯誤'耙子中止! 找不到表格'dbrick' 任務:TOP => db:migrate =>環境 (請參閱完整跟蹤,通過運行帶有--trace的任務)' – Abhiram 2012-08-02 15:09:02

+0

@Abhiram多數民衆贊成在奇怪。在創建dbrick創建遷移之前,也許你的某個遷移正在使用表dbrick。 – Karan 2012-08-02 15:11:36