0

I am trying to build the sample app in Rails Tutorial 3rd edition. On Chapter 11, it starts with adding a new model for microposts. However, When run the migrate, it throws below error

== 20141212145132 CreateEntries: migrating ==================================== -- create_table(:microposts) -- add_index(:microposts, [:user_id, :created_at]) rake aborted! StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: no such table: main.microposts: CREATE INDEX "index_entries_on_user_id_and_created_at" ON "microposts" ("user_id", "created_at")/

2
  • Can you post the migration file code? Commented Dec 17, 2014 at 6:32
  • class CreateEntries < ActiveRecord::Migration def change create_table :microposts do |t| t.text :content t.references :user, index: true t.timestamps add_index :microposts, [:user_id, :created_at] end end end Commented Dec 17, 2014 at 6:34

2 Answers 2

2

Try changing these lines

class CreateMicroposts < ActiveRecord::Migration  # <==== convention 
  def change 
    create_table :microposts do |t| 
      t.text :content 
      t.references :user, index: true 
      t.timestamps 
      t.index [:user_id, :created_at]  # <=== 
    end 
  end 
end
Sign up to request clarification or add additional context in comments.

Comments

1

Ok, I got it now what I was doing wrong.

I had added the "add index" at the end of the of "def change" instead of after it. This is the code which is working now...

class CreateEntries < ActiveRecord::Migration
  def change
    create_table :entries do |t|
      t.text :content
      t.references :user, index: true

      t.timestamps
    end
  add_index :entries, [:user_id, :created_at]
  end
end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.