Q:

Mysql2::Error: Key column 'hotel_user_id' doesn't exist in table

I have:
def change

  create_table :orders do |t|
    t.string :name
    t.text :address,:limit=>500
    t.string :email
    t.string :pay_type
    t.string :phone,:limit=>25
    t.integer :hotel_user_id
    t.timestamps
  end

  add_index("hotel_users","hotel_user_id")
end

Error in log:
$ rake db:migrate
== 20140822140639 CreateOrders: migrating ====================================
-- create_table(:orders)
   -> 0.0790s

-- add_index("hotel_users", "hotel_user_id")
rake aborted! 

StandardError: An error has occurred, all later migrations canceled:

Mysql2::Error: Key column 'hotel_user_id' doesn't exist in table: CREATE  INDEX index_hotel_users_on_hotel_user_id`  ON 'hot
el_users' ('hotel_user_id') F:/OrderBooking/db/migrate/20140822140639_create_orders.rb:12:in 'change'
c:in 'migrate'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)'

I have a table hotel_users which has many orders. I orders table i want to set a foreign key. But i am getting the above error while creating the table.  

A:

The problem is that the column hotel_user_id exists in the orders table and you are creating the index on the same column on the hotel_users table.