1

我正在尝试安装 Ancestry gem,但我遇到了rake db:migrate.

我正在按照 Ancestry github 页面上的说明进行操作。完成后,我rails g migration add_ancestry_to_message ancestry:string 将迁移文件(在 railcast #262 之后)编辑为:

class AddAncestryToMessage < ActiveRecord::Migration
  def self.up
    add_column :messages, :ancestry, :string
    add_index :messages, :ancestry
  end

  def self.down
    remove_index :messages, :ancestry
    remove_column :messages, :ancestry
  end
end

当我然后运行rake db:migrate时,我收到以下错误:

==  AddAncestryToMessage: migrating ===========================================
-- add_column(:messages, :ancestry, :string)
rake aborted!
An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: no such table: Shipmgr: ALTER TABLE "Message" ADD "ancestry" varchar(255)

Tasks: TOP => db:migrate

我已经在新创建的 Rails 应用程序和现有的 Rails 应用程序上尝试过这个,但我仍然无法让它工作。有人对这个问题有什么建议吗?

4

1 回答 1

0

您应该尝试将迁移类名称更改为复数(表格)形式“消息”:

class AddAncestryToMessages < ActiveRecord::Migration

或者,更准确地说,将迁移生成器命令更改为:

rails g migration add_ancestry_to_messages ancestry:string
于 2012-01-11T23:39:01.390 回答