Ruby On Rails Heroku db:迁移已中止!
我已将我的应用程序推送到 Heroku,现在尝试运行“$ heroku rake db:migrate”。我收到此错误:
PGError:错误:关系“库存”不存在 :从“库存”中选择“库存”。*
在我的本地计算机上,一切正常。本地正在使用 SQLite 3。此外,该应用程序的以前版本运行得很好 - 以前的版本确实包含库存模型。现在,我已经阅读了(几乎)stackoverflow 上和网络上有关此问题的所有帖子,但我仍然找不到解决方法。有人对让它发挥作用有什么建议吗?
红宝石 1.9.2 ROR 3
更新.. 以下是创建 inventory 表的迁移的来源:
class CreateInventories < ActiveRecord::Migration
def self.up
create_table :inventories do |t|
t.decimal :initial_amount, :precision => 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
I've pushed my app to Heroku and now am trying to run '$ heroku rake db:migrate'. I get this error:
PGError: ERROR: relation "inventories" does not exist
: SELECT "inventories".* FROM "inventories"
On my local machine everything works great. The local is using SQLite 3. Also, previous versions of the app worked just fine -- the previous versions did include the inventories model. Now, I've read ( almost ) every post on stackoverflow and on the web about this issue, but I still cannot find a way around it. Does anybody have any advice on getting this to work?
Ruby 1.9.2
ROR 3
UPDATE..
Here is the source to the migration that creates the inventories table:
class CreateInventories < ActiveRecord::Migration
def self.up
create_table :inventories do |t|
t.decimal :initial_amount, :precision => 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您在迁移中使用过 Inventory 模型吗?也许您在迁移过程中出现了错误,例如您在迁移本地数据库后编辑了迁移文件?
无论如何,运行 rake --trace db:migrate 应该会显示整个错误消息以及堆栈跟踪 - 您将找到有问题的代码行。
更新:
在您的堆栈跟踪中(链接位于评论中)有一个可疑行:
有什么代码?
Have you used the Inventory model in your migration? Maybe you have an error in your migration, for example you edited the migration file after you migrated your local database?
In any case, running
rake --trace db:migrate
should show you the whole error message, together with stack trace - you will find the problematic line of code.UPDATE:
In your stack trace (link is in the comment) there is one suspicious line:
What code is there?
解决方案:我终于弄清楚了这个问题。我的用户模型中有这个方法:
由于某种原因,这导致了错误。我将其更新为使用
@user.inventories
和@user.cups
。谢谢大家。SOLUTION: I finally figured out the issue. I had this method in my user model:
For some reason, that caused errors. I updated it to use
@user.inventories
and@user.cups
instead. Thanks everybody.该错误表明该表在远程不存在。看看这个:
http://docs.heroku.com/database#common-issues-migration -to-postgresql
我希望之前的 db:migrate 已经创建了该表,除非数据库更改发生在 rake db 任务之外。我发现很容易使其不同步。您可以通过指定所需的迁移方法(向上或向下)以及要执行的迁移的时间戳来运行特定的迁移。示例:
这将运行 2010 年 11 月 8 日上午 9:21:53 生成的迁移。您可以浏览 db/ 文件夹中的迁移以查找包含缺失表的迁移。
The error indicates that the table does not exist remotely. See this:
http://docs.heroku.com/database#common-issues-migrating-to-postgresql
I would expect a previous db:migrate to have created the table, unless database changes have occurred outside of the rake db task. I find that it's rather easy to get this out of sync. You can run specific migrations by specifying the migration method desired (up or down) and the timestamp of the migration to be executed. An example:
This runs the migration generated on 11/8/2010 at 9:21:53 AM. You can browse your migrations in the db/ folder to find the migration that contains the missing table.