我进行了一次新迁移,以便在我的成分有效记录中添加 price 列。尽管如此,当我运行 rails db:migrate 时,仍然收到错误消息,指出表成分不存在。这是我的控制台命令:
C:\Users\andri\Desktop\hoagieShop\hoagieShop>rails generate migration
AddPriceToIngredients price:decimal, false:null --force
invoke active_record
remove db/migrate/20190124075954_add_price_to_ingredients.rb
create db/migrate/20190124080657_add_price_to_ingredients.rb
C:\Users\andri\Desktop\hoagieShop\hoagieShop>rails db:migrate
== 20190123201200 RemovePriceFromIngrendients: migrating
======================
-- remove_column(:ingrendients, :price, :decimal)
rails aborted!
StandardError: An error has occurred, this and all later migrations
canceled:
Could not find table ingrendients
C:/Users/andri/Desktop/hoagieShop/hoagieShop/db/migrate/201901232
01200_remove_price_from_ingrendients.rb:3:in change
bin/rails:4:in require
bin/rails:4:in <main>
Caused by:
ActiveRecord::StatementInvalid: Could not find table ingrendients
C:/Users/andri/Desktop/hoagieShop/hoagieShop/db/migrate/20190123201200_
remove_pr
ice_from_ingrendients.rb:3:in change
bin/rails:4:in require
bin/rails:4:in <main>
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
我已删除并再次添加了此迁移几次,因此我不确定它是否起任何作用。 有谁知道为什么会这样吗?感谢您的帮助!
答案 0 :(得分:2)
这似乎是您20190123201200_remove_price_from_ingrendients.rb
迁移中的简单错字,而不是您生成的迁移中的错字,请参阅:
-- remove_column(:ingrendients, :price, :decimal)
可能应该是ingredients
而不是ingrendients
(在n
之前的dients
之外)