【问题标题】:PGError: ERROR: relation "schema_migrations" does not exist when I heroku db:pushPGError:错误:当我使用 heroku db:push 时,关系“schema_migrations”不存在
【发布时间】:2012-02-13 04:08:48
【问题描述】:

我的本​​地系统上有一个 PostGresql 数据库。我在开发过程中使用了它,我正在尝试在 Heroku 系统上对其进行测试。

请注意,我正在使用 PostGresql,以便可以使用架构。

我在本地系统上完美运行该系统。

我去 Heroku 页面了解如何将我的数据库推送到服务器。 http://devcenter.heroku.com/articles/taps

> heroku db:push

大约 5 分钟后我得到了

"PGError: ERROR:  relation "schema_migrations" does not exist"

我想知道的是两个方面.. 在次要层面上,我想知道为什么会这样。我的数据库是从头开始重建的吗? 在主要层面上,我想知道如何解决这个问题。

简介:如何绕过 db:push 上丢失的表?


解决给出的答案中表达的问题。

W:\RUBY\EDM>heroku run rake db:create
Running rake db:create attached to terminal... up, run.1
kzcgkswrss already exists

W:\RUBY\EDM>heroku run rake db:migrate
Running rake db:migrate attached to terminal... up, run.1

W:\RUBY\EDM>heroku db:push
Loaded Taps v0.3.23
Auto-detected local database: postgres://postgres:password@127.0.0.1/EDM2_develo
pment?encoding=utf8
Warning: Data in the app 'xxxx' will be overwritten and will not be r
ecoverable.

 !    WARNING: Potentially Destructive Action
 !     This command will affect the app: xxxx
 !    To proceed, type "xxxx" or re-run this command with --confirm c
xxxx

> xxxxx

Sending schema
Schema:        100% |==========================================| Time: 00:01:56
Sending indexes
schema_migrat: 100% |==========================================| Time: 00:00:01
....
users:         100% |==========================================| Time: 00:00:02
Sending data
31 tables, 5 records
schema_migrat:   0% |                                          | ETA:  --:--:--
Saving session to push_201202150351.dat..
!!! Caught Server Exception
HTTP CODE: 500
Taps Server Error: PGError: ERROR:  relation "schema_migrations" does not exist

编辑 2

似乎此错误与 postGresql 中存在的第二个模式有关。 看起来它推送了所有公开的空表,但是一旦它尝试推送第二个架构,它就失败了..

【问题讨论】:

  • 我真的很想了解在现有数据库上,所述数据库的上传会导致除了目标系统上的副本之外的任何内容。
  • 我刚刚编辑了我的代码。有人建议我先运行迁移。在这里,我就是这样做的。尽管推送后的警告表明它没有实际意义。所以现在.. 到错误.. 一个人如何度过它?

标签: ruby-on-rails database postgresql heroku


【解决方案1】:

试试

 heroku rake db:push

或者如果这不起作用,那么做

 heroku rake db:migrate

首先,然后尝试第二个。

你得到了丢失的表,因为你还没有在 Heroku 上创建表。您需要创建数据库并运行迁移。是的,这将创建一个新数据库。

更新:

引用 Daniel Vandersluis(来自this link):

当您使用 rails 迁移时,会自动创建一个名为 schema_migrations 的表,该表通过存储每个迁移的版本号来跟踪已应用的迁移(这是文件名中迁移名称前面的数字,即 db/migrate/_20090617111204__migration.rb)。当您运行 rake db:migrate 向上迁移时,只会运行以前未运行过的迁移(即它们的版本不包含在表中)(因此,更改已执行的迁移将无效运行 db:migrate 时)。向下迁移时,在 schema_migrations 中找到的高于您要回滚到的版本的所有版本都将被撤消。

【讨论】:

  • “heroku db:push”就在 heroku 网站上。所以我希望它是对的。
  • 有问题的表不会是迁移的一部分。我知道我没有创建它。它是由 rails 创建的迁移记录。
  • 最后.. 由于表在我要推送的数据库中,为什么我必须做一些特别的事情?不应该做一个 db:push 复制源数据库的结构吗?
  • OH snot forgot.. 因为我的数据库中的表取决于一个表(my_schema)中的数据而存在,我必须运行一个创建 rake 的模式。我怎么能期望 db:push 知道要运行什么迁移?
  • 另外,您可能希望保留 schema_migrations 表。请参阅“关于 schema_migrations 表”下的 api.rubyonrails.org/classes/ActiveRecord/Migration.html
【解决方案2】:

您是否在 heroku 本身上运行迁移?

$ heroku run rake db:migrate 

如果你没有,那么可能就是这样

【讨论】:

    猜你喜欢
    • 2011-07-23
    • 2012-12-20
    • 2012-01-13
    • 2012-04-27
    • 2014-01-18
    • 1970-01-01
    • 2013-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多