Question

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?

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top