祖先分贝:迁移(Ancestry db:migrate)

2019-09-28 04:42发布

我试图安装祖先的宝石,但我有问题rake db:migrate

我下面的祖先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应用程序,但我仍然无法得到这个工作。 有没有人有任何关于此问题的意见?

Answer 1:

你应该尝试改变迁移类名称的使用复数(表)形式的“消息”:

class AddAncestryToMessages < ActiveRecord::Migration

或者,更准确地,更改迁移发生器命令:

rails g migration add_ancestry_to_messages ancestry:string


文章来源: Ancestry db:migrate