Ancestry db:migrate

五迷三道 提交于 2019-12-11 11:09:16

问题


I am trying to install the Ancestry gem but I am having problems with rake db:migrate.

I am following the instructions on the Ancestry github page. After I have done rails g migration add_ancestry_to_message ancestry:string I am editing the migration file (following railcast #262) to be:

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

When I then run rake db:migrate I am getting the following error:

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

I have tried this on a newly created rails app and on an existing rails app but I am still unable to get this to work. Does anyone have any advice on this issue?


回答1:


You should try changing the migration class name to the pluralized (table) form 'Messages':

class AddAncestryToMessages < ActiveRecord::Migration

or, more accurately, change the migration generator command to:

rails g migration add_ancestry_to_messages ancestry:string


来源:https://stackoverflow.com/questions/8828204/ancestry-dbmigrate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!