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.
问题是订单表中存在hotel_user_id
列,并且您正在hotel_users
表的同一列上创建索引。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.