2012-08-02 96 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