Ruby On Rails Heroku db:migrate Aborted!

我已将我的应用程序推送到Heroku,现在我正在尝试运行’$ heroku rake db:migrate’。 我收到此错误:

PGError:错误:关系“库存”不存在:选择“库存”。*来自“库存”

在我的本地机器上一切都很棒。 本地使用SQLite 3.此外,该应用程序的早期版本工作得很好 – 以前的版本确实包括库存模型。 现在,我已经阅读(几乎)关于stackoverflow和网络上关于这个问题的每篇文章,但我仍然无法找到解决方法。 有没有人建议让它工作?

Ruby 1.9.2 ROR 3

更新..以下是创建库存表的迁移的来源:

class CreateInventories  10, :scale => 2 t.decimal :remaining_amount, :precision => 10, :scale => 2 t.string :unit t.decimal :cost, :precision => 10, :scale => 2 t.integer :type_id t.integer :brand_id t.integer :blend_id t.integer :user_id t.boolean :in t.timestamps end end def self.down drop_table :inventories end end 

您是否在迁移中使用了Inventory模型? 也许您的迁移有错误,例如您在迁移本地数据库后编辑了迁移文件?

在任何情况下,运行rake --trace db:migrate都应该显示整个错误消息,以及堆栈跟踪 – 您将找到有问题的代码行。

更新:

在您的堆栈跟踪(链接在注释中)中有一条可疑行:

 ...0-d4e1268c8981/mnt/config/environment.rb:5 

有什么代码?

解决方案:我终于弄明白了这个问题。 我的用户模型中有这个方法:

 def self.search( id ) @inventory = Inventory.where(:primary_user [id]) @cups = Cup.where(:user_id [id]) @inventory + @cups end 

出于某种原因,这导致了错误。 我将其更新为使用@user.inventories@user.cups 。 谢谢大家。

该错误表示该表不存在远程。 请参阅: http : //docs.heroku.com/database#common-issues-migrating-to-postgresql

我希望以前的db:migrate能够创建表,除非在rake db任务之外发生了数据库更改。 我发现让它不同步很容易。 您可以通过指定所需的迁移方法(向上或向下)以及要执行的迁移的时间戳来运行特定迁移。 一个例子:

 heroku rake db:migrate:up VERSION=20101108092153 

这将运行2010年11月8日上午9:21:53生成的迁移。 您可以在db /文件夹中浏览迁移,以查找包含缺失表的迁移。