PG::UndefinedTable: ERROR: table "table-name" does not exist
PG::UndefinedTable: ERROR: table "table-name" does not exist
我正在弄乱我的数据库,创建和删除 tables。将它们推送到 heroku 后,我删除了一些迁移文件。之前我创建了一个table 'moms'。后来想重命名,就把'moms'删了,新建了table'minutes_of_meetings'。我做了 $rake db:migrate,一切都成功完成,我的应用程序 运行 在本地主机上完美运行。
将其推送到 heroku 后,当我执行 $heroku 运行 rake db:migrate 时,它生成了以下日志:
ActiveRecord::SchemaMigration Load (0.7ms) SELECT "schema_migrations".* FROM "schema_migrations"
Migrating to DropMoms (20150823142852)
(0.6ms) BEGIN
== 20150823142852 DropMoms: migrating =========================================
-- drop_table(:moms)
(0.9ms) DROP TABLE "moms"
PG::UndefinedTable: ERROR: table "moms" does not exist
: DROP TABLE "moms"
(0.5ms) ROLLBACK
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: table "moms" does not exist
: DROP TABLE "moms"/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
我在 heroku 中新建了一个 table 'moms' 以便在迁移 运行 时可以将其删除。我这样做了:
$ heroku run Ruby console for rails-app-name >> ActiveRecord::Migration.create_table :moms
我还创建了一个迁移来创建 table 'moms'。但错误仍然存在。
编辑:
这是我的 CreateMoms 迁移文件:
class CreateMoms < ActiveRecord::Migration
def change
create_table :moms do |t|
t.string :name
t.timestamp null: false
end
end
end
当我 运行 heroku 运行 rake db:migrate:up
Running `rake db:migrate:up` attached to terminal... up, run.1729
rake aborted!
VERSION is required
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:78:in `block (3 levels) in <top (required)>'
Tasks: TOP => db:migrate:up
(See full trace by running task with --trace)
WARNING: Toolbelt v3.41.3 update available.
在 heroku 上 运行 rake db:migrate:down
Running `rake db:migrate:down` attached to terminal... up, run.6389
rake aborted!
VERSION is required - To go down one migration, run db:rollback
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:86:in `block (3 levels) in <top (required)>'
Tasks: TOP => db:migrate:down
(See full trace by running task with --trace)
WARNING: Toolbelt v3.41.3 update available.
注意
rake db:schema:load
将从 heroku 数据库中清除所有数据。请确保您在 heroku 上有数据备份。如果您还没有 heroku 数据库的备份,您可以使用 Heroku PGBackups
轻松备份
看起来你的 schema
搞砸了。只需使用 rake db:schema:load
将模式加载到数据库,然后再次 运行 迁移:
heroku run rake db:schema:load
heroku run rake db:migrate
我正在弄乱我的数据库,创建和删除 tables。将它们推送到 heroku 后,我删除了一些迁移文件。之前我创建了一个table 'moms'。后来想重命名,就把'moms'删了,新建了table'minutes_of_meetings'。我做了 $rake db:migrate,一切都成功完成,我的应用程序 运行 在本地主机上完美运行。
将其推送到 heroku 后,当我执行 $heroku 运行 rake db:migrate 时,它生成了以下日志:
ActiveRecord::SchemaMigration Load (0.7ms) SELECT "schema_migrations".* FROM "schema_migrations"
Migrating to DropMoms (20150823142852)
(0.6ms) BEGIN
== 20150823142852 DropMoms: migrating =========================================
-- drop_table(:moms)
(0.9ms) DROP TABLE "moms"
PG::UndefinedTable: ERROR: table "moms" does not exist
: DROP TABLE "moms"
(0.5ms) ROLLBACK
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: table "moms" does not exist
: DROP TABLE "moms"/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
我在 heroku 中新建了一个 table 'moms' 以便在迁移 运行 时可以将其删除。我这样做了:
$ heroku run Ruby console for rails-app-name >> ActiveRecord::Migration.create_table :moms
我还创建了一个迁移来创建 table 'moms'。但错误仍然存在。
编辑:
这是我的 CreateMoms 迁移文件:
class CreateMoms < ActiveRecord::Migration
def change
create_table :moms do |t|
t.string :name
t.timestamp null: false
end
end
end
当我 运行 heroku 运行 rake db:migrate:up
Running `rake db:migrate:up` attached to terminal... up, run.1729
rake aborted!
VERSION is required
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:78:in `block (3 levels) in <top (required)>'
Tasks: TOP => db:migrate:up
(See full trace by running task with --trace)
WARNING: Toolbelt v3.41.3 update available.
在 heroku 上 运行 rake db:migrate:down
Running `rake db:migrate:down` attached to terminal... up, run.6389
rake aborted!
VERSION is required - To go down one migration, run db:rollback
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:86:in `block (3 levels) in <top (required)>'
Tasks: TOP => db:migrate:down
(See full trace by running task with --trace)
WARNING: Toolbelt v3.41.3 update available.
注意
rake db:schema:load
将从 heroku 数据库中清除所有数据。请确保您在 heroku 上有数据备份。如果您还没有 heroku 数据库的备份,您可以使用 Heroku PGBackups
看起来你的 schema
搞砸了。只需使用 rake db:schema:load
将模式加载到数据库,然后再次 运行 迁移:
heroku run rake db:schema:load
heroku run rake db:migrate