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

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

so my application has messages that you can post (kind of like twitter) and Im adding replies, and I am using the ancestry gem to do so.

my code in my schema.rb file ( I think this is the file it uses to create tables every time you run rake db:migrate. but I could be wrong (This could be the problem!)

  create_table "messages", :force => true do |t|
    t.string   "content"
    t.integer  "user_id"
    t.datetime "created_at", :null => false
    t.datetime "updated_at", :null => false
    t.string   "ancestry"
  end

  add_index "messages", ["user_id", "created_at", "ancestry"], :name =>   "index_messages_on_user_id_and_created_at_and_ancestry"
mu is too short
  • 426,620
  • 70
  • 833
  • 800
BigBoy1337
  • 4,735
  • 16
  • 70
  • 138

1 Answers1

0

Oh, now I see: you added your code to the schema.rb but you had to use migrations. Remove your manually added code from schema.rb and run:

rails g migration CreateMessages

You'll get the file db/migrate/[timestamp]_create_messages.rb. Fill its change method with your code and then run (it should be created for you, but empty. For old versions it is named up):

rake db:migrate

This command will change your schema.rb by itself. Don't change it manually! (at lest till you become a mature Rails-programmer).

jdoe
  • 15,665
  • 2
  • 46
  • 48
  • hmm that didnt work for me. I took out the t.string "ancestry" and the "ancestry" from the add_index method therefore changing it back to its original state. then I ran rails g migration CreateMessages and it created the rb file for me. Then I copied and pasted all my code above into up. Is this all correct? – BigBoy1337 May 08 '12 at 08:28
  • Wait a minute. *Changing it back to its original state* -- what did you mean? You already have table and just want to add index to it? If all you need is to add an index to the table you have then your `up`/`change` method should contain ONLY `add_index ....`. Also if you have `up` method then fill the `down` method with `remove_index, :name => "..."`. – jdoe May 08 '12 at 09:26
  • @user1123905, almost correct. In the up of the new rb file, you should call add_column and add_index, since as jdoe noted, you already have the table. – Marlin Pierce May 08 '12 at 11:31