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 /文件夹中浏览迁移,以查找包含缺失表的迁移。
- Heroku Rails Net :: HTTP:OpenSSL :: SSL :: SSLError:SSL_connect返回= 1 errno = 0状态= SSLv3读取服务器证书B:证书validation失败
- Rails app中的内存不断增加
- heroku运行db:migrate因rake中止而失败
- 无法在生产中实例化模块
- 阻止资产在本地进行预编译,以进行heroku rails asset_sync s3应用程序的本地生产测试
- 生产失败/ heroku:WHERE a.attrelid =’“学校”’:: regclass
- 在Heroku上托管的ROR中,在2个站点上显示一个具有不同前端但相同后端的应用程序
- Github和heroku上的App:忽略一个文件而不是另一个文件
- Heroku:无法通过Bundler安装gem