0
votes

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? - roob
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 - Harish Garg

2 Answers

2
votes

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
1
votes

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