我正在尝试安装Ancestry gem,但我遇到了rake db:migrate
的问题。
我按照Ancestry github页面上的说明操作。完成rails g migration add_ancestry_to_message ancestry:string
后
我正在编辑迁移文件(在#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应用程序上尝试了这个,但我仍然无法让它工作。有没有人对这个问题有任何建议?
答案 0 :(得分:0)
您应该尝试将迁移类名称更改为复数(表格)表单“消息”:
class AddAncestryToMessages < ActiveRecord::Migration
或者更确切地说,将migration generator命令更改为:
rails g migration add_ancestry_to_messages ancestry:string