PGError:错误:当我使用heroku db:push时,关系“schema_migrations”不存在

时间:2021-05-20 18:04:16

I've a PostGresql database on my local system. I used it during development and I'm trying to test it out on the Heroku system.

我在本地系统上有一个PostGresql数据库。我在开发过程中使用过它,我试图在Heroku系统上测试它。

Note I'm using PostGresql so that I can make use of the schemas.

注意我正在使用PostGresql,以便我可以使用模式。

I'm running the system perfectly on my local system.

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

I go to the Heroku page on how to push my DB to the server. http://devcenter.heroku.com/articles/taps

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

> heroku db:push

After about 5 minutes I get

大约5分钟后,我得到了

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

What I'm wondering is two fold.. On a minor level I am wondering why this is happening. Is my database being reconstructed from scratch? On a major level, I'm wondering how to I get around this.

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

Brief: How do I get around the missing table on a db:push?

简介:如何绕过db上的缺失表:推送?


To address concerns expressed in the answer given.

解决在给出的答案中表达的担忧。

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

edit 2

It seems this error is related to a second schema that exists in postGresql.. It looks like it pushed all the empty tables in the public, but as soon as it tried to push up the second schema, it failed..

看来这个错误与postGresql中存在的第二个模式有关。看起来它推动了公共中的所有空表,但是一旦它试图推高第二个模式,它就失败了..

2 个解决方案

#1


1  

Try

尝试

 heroku rake db:push

Or perhaps if that doesn't work, do

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

 heroku rake db:migrate

first, and then try the second.

首先,然后尝试第二个。

You're getting the missing table because you haven't created the table yet on Heroku. You need to create the DB and run the migrations. Yes, this will create a new DB.

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

UPDATE:

更新:

To quote Daniel Vandersluis (from this link):

引用Daniel Vandersluis(来自此链接):

When you use rails migrations, a table called schema_migrations is automatically created, which keeps track of what migrations have been applied, by storing the version number of each migration (this is the number that prefaces the migration name in the file name, ie db/migrate/_20090617111204__migration.rb). When you run rake db:migrate to migrate up, only migrations which have not been run previously (ie. their version is not contained in the table) will be run (for this reason, changing a migration that's already been executed will have no effect when running db:migrate). When migrating down, all versions found in schema_migrations that are greater than the version you are rolling back to will be undone.

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

#2


0  

did you run your migrations on heroku itself?

你是否在heroku上运行迁移?

$ heroku run rake db:migrate 

If you didn't then probably that's it

如果你没有那么可能那就是它

#1


1  

Try

尝试

 heroku rake db:push

Or perhaps if that doesn't work, do

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

 heroku rake db:migrate

first, and then try the second.

首先,然后尝试第二个。

You're getting the missing table because you haven't created the table yet on Heroku. You need to create the DB and run the migrations. Yes, this will create a new DB.

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

UPDATE:

更新:

To quote Daniel Vandersluis (from this link):

引用Daniel Vandersluis(来自此链接):

When you use rails migrations, a table called schema_migrations is automatically created, which keeps track of what migrations have been applied, by storing the version number of each migration (this is the number that prefaces the migration name in the file name, ie db/migrate/_20090617111204__migration.rb). When you run rake db:migrate to migrate up, only migrations which have not been run previously (ie. their version is not contained in the table) will be run (for this reason, changing a migration that's already been executed will have no effect when running db:migrate). When migrating down, all versions found in schema_migrations that are greater than the version you are rolling back to will be undone.

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

#2


0  

did you run your migrations on heroku itself?

你是否在heroku上运行迁移?

$ heroku run rake db:migrate 

If you didn't then probably that's it

如果你没有那么可能那就是它