0


昨天,我试图建立一个名为“Elasticsearch”的全文搜索引擎,我按照 Railscasts.com 上的说明进行操作(http://railscasts.com/episodes/306-elasticsearch-part-1?view=comments&_= 1345840910957)将此搜索引擎集成到我的网站上。我按照任务调用'rake db:setup',它“重新创建”了我的整个数据库(不想要那个),现在没有任何效果。
似乎 Rails 从 schema.rb 重新创建了数据库,但它只创建表和索引,而不是与之关联的列。 http://img14.imageshack.us/img14/1535/bildschirmfoto20120825u.png
我在 _development 数据库上。

运行rake db:setup看起来像这样:

doanything_development already exists 
doanything_test already exists
-- create_table("admin_notes", {:force=>true})
NOTICE:  CREATE TABLE will create implicit sequence "admin_notes_id_seq" for serial column "admin_notes.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "admin_notes_pkey" for table "admin_notes"
   -> 0.1088s
-- add_index("admin_notes", ["admin_user_type", "admin_user_id"], {:name=>"index_admin_notes_on_admin_user_type_and_admin_user_id"})
   -> 0.0064s
-- add_index("admin_notes", ["resource_type", "resource_id"], {:name=>"index_admin_notes_on_resource_type_and_resource_id"})
   -> 0.0049s ...<br /><br />
Schema.rb looks like: " create_table "users", :force => true do |t|<br />
    t.string   "name"
    t.string   "email"
    t.datetime "created_at",:null => false
    t.datetime "updated_at",:null => false ... end <br />

它在我的 pgdb 表“序列”列上创建,"users_id_seq"我以前没有。运行“ rake db:migrate”不会加载任何现有的迁移文件:例如

class AddSaltToUsers < ActiveRecord::Migration <br/>
  def change <br/>
    add_column :users, :salt, :string <br/>
  end
end

版本是:ruby 1.9.3p194、Rails 3.2.6 和 PostgreSQL 9.1.4

如果有人能弄清楚刚刚发生了什么以及我如何让我的网站再次运行。

4

1 回答 1

1

If you ran rake db:migrate once. The migration for AddSaltToUsers may have already ran. If so, there are a few ways to overcome this.

Either create a new migrations file, or manually edit schema_migrations, by removing the version number from that table and then re-running rake db:migrate. I would highly not recommend doing the latter, as it can screw up your migrations all together if you don't know what you are doing.

Hope that helps.

于 2012-08-25T09:09:42.010 回答