gpt4 book ai didi

Mysql2::错误:表中不存在键列 'hotel_user_id'

转载 作者:行者123 更新时间:2023-11-29 23:26:37 25 4
gpt4 key购买 nike

我有:

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

日志中的错误:

$ 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)'

我有一个表hotel_users,其中有许多订单。我在订单表中想设置外键。但是在创建表时出现上述错误。

最佳答案

问题是订单表中存在 hotel_user_id 列,而您正在 hotel_users 表的同一列上创建索引。

关于Mysql2::错误:表中不存在键列 'hotel_user_id',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26902116/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com