简体   繁体   English

Ruby on Rails-运行服务器时出错

[英]Ruby on Rails - error running server

am currently working on a rails project. 目前正在从事Rails项目。 When i tried to start rails server its throwing the following error: 当我尝试启动Rails Server时,抛出以下错误:

=> 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)

My table name is 'dbrick'. 我的表名为“ dbrick”。 I also Tried to rake db:drop and rake db:mirgrate. 我也尝试过耙db:drop和耙db:mirgrate。 While migrating its throwing the following error: 在迁移时抛出以下错误:

rake aborted!
Could not find table 'dbrick'

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

This is my migrate file: 这是我的迁移文件:

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

It will be so much help full if any one help me out of this. 如果有人能帮助我,这将有很大的帮助。 Thanks in advance. 提前致谢。

I would try : 我会尝试 :

rake db:schema:load

To load your schema ( to which I believe its finding the error against your DB ). 加载您的架构(我相信它会针对您的数据库找到错误)。

If that fails, I would manually find the migration that creates your dbrick, locate the name of the file and copy and paste the number in the filename to produce this : 如果失败,我将手动找到创建您的dbrick的迁移,找到文件的名称,然后将数字复制并粘贴到文件名中以生成以下内容:

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

Look for errors. 寻找错误。 Occasionally one thing exists already, or doesn't exist already and prevents the migration from running all the way, and consequentially that would be the source of your error. 有时候,一件事已经存在或不存在,并阻止迁移一直运行,因此这可能是错误的根源。 If it goes successfully then rake it back up : 如果成功,则将其耙回:

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

If it doesn't go successfully, then you'll have to put on your miner's helmet, and get your hands dirty with : 如果操作失败,则必须戴上矿工的头盔,并用以下方法弄脏手:

rails dbconsole

Which will take you into your database and you'll have to manually delete whatever table/column is preventing the migration from occurring. 它将带您进入数据库,并且您必须手动删除阻止迁移发生的任何表/列。 Once that is fixed, exit out and rake db:migrate:up ! 一旦解决,退出并rake db:migrate:up

Have you migrated your database? 您是否迁移了数据库? rake db:migrate

If you have, drop your database (this deletes all data, so be careful - do it if you do not care about losing data in your db) 如果有,请删除数据库(这将删除所有数据,因此请小心-如果您不关心丢失数据库中的数据,请这样做)

rake db:drop

This will clear out your database, and your schema. 这将清除您的数据库和架构。 Then 然后

rake db:migrate

This will re-migrate your schema. 这将重新迁移您的架构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM