PG::UndefinedTable: ERROR: table "table-name" does not exist

fhaider

I was messing with my database, creating and deleting tables. I deleted few migration files after pushing them to heroku. Previously I created a table 'moms'. Later I wanted to rename it, so I deleted 'moms' and created new table 'minutes_of_meetings'. I did $rake db:migrate and everything was done successfully and my app is running perfectly on localhost.

After pushing it to heroku, when I did $heroku run rake db:migrate, it generated the following log:

  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'

I created a new table 'moms' in heroku so that it can be deleted when migration runs. I did this:

$ heroku run Ruby console for rails-app-name >> ActiveRecord::Migration.create_table :moms 

I also created a migration to create table 'moms'. But still the error persists.

EDIT:

This is my CreateMoms migration file:

class CreateMoms < ActiveRecord::Migration
  def change
    create_table :moms do |t|
      t.string :name
      t.timestamp null: false
    end
  end
end

When I run heroku run 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.

On heroku run 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.
K M Rakibul Islam

Caution

rake db:schema:load will wipe away all of your data from the heroku database. Please make sure you have your data backup on heroku. If you already don't have backup of your heroku database, you can easily do so by using Heroku PGBackups

Looks like your schema is messed up. Just load the schema to the database using rake db:schema:load and then run the migration again:

heroku run rake db:schema:load
heroku run rake db:migrate

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Rails: PG::UndefinedTable: ERROR: relation "..." does not exist

From Dev

PG::UndefinedTable: ERROR: relation does not exist

From Dev

PG::UndefinedTable: ERROR: relation "musicians" does not exist

From Dev

PG::UndefinedTable: ERROR: relation 'caves' does not exist

From Dev

rake aborted! PG::UndefinedTable: ERROR: relation "pages" does not exist

From Dev

rake aborted! PG::UndefinedTable: ERROR: relation "pages" does not exist

From Dev

ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "guestbooks" does not exist

From Dev

Table name as PostgreSQL function parameter / ERROR: column ".." does not exist

From Dev

ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "spree_orders" does not exist

From Dev

heroku postgresql database rails app PG::UndefinedTable: ERROR: relation "comments" does not exist

From Dev

PG::UndefinedTable: ERROR: relation "" does not exist - Amazon EC2, Postgresql, and Rails 5

From Dev

relation "table name" does not exist (postgresql)

From Dev

PGERROR: ERROR relation "table_name" does not exist (avoiding git commits)

From Dev

Rails PG::UndefinedTable: ERROR: missing FROM-clause entry for table

From Dev

PG::UndefinedTable: ERROR: missing FROM-clause entry for table

From Dev

PG::UndefinedTable: ERROR: missing FROM-clause entry for table

From Dev

Pg:Error column does not exist

From Dev

Heroku database error on production: PG::UndefinedTable Error

From Dev

Sidekiq PG::UndefinedColumn: ERROR: does not exist

From Dev

PG::UndefinedTable: ERROR: missing FROM-clause entry for table when using joins and where

From Dev

PG::UndefinedTable: ERROR: missing FROM-clause entry for table when using SELECT DISTINCT ON

From Dev

PG::UndefinedTable: ERROR: missing FROM-clause

From Dev

Bizarre PG::UndefinedTable Error with Rails app on Heroku

From Dev

PG::UndefinedTable ERROR ruby on rails heroku

From Dev

Heroku/Rails: PG:: Undefined Table: error "[tablename]" does not exist on heroku rails migration

From Dev

PHP pg_prepare() table name as parameter

From Dev

jdbc with embedded derby in javafx application: Table/View 'TABLE NAME' does not exist exception

From Dev

Rails 4: join queries with parent entity table, error: PG::UndefinedTable: ERROR: missing FROM-clause entry for table "states"

From Dev

A relation "table_name" does not exist in "Many2many relation" in Odoo 10.0

Related Related

  1. 1

    Rails: PG::UndefinedTable: ERROR: relation "..." does not exist

  2. 2

    PG::UndefinedTable: ERROR: relation does not exist

  3. 3

    PG::UndefinedTable: ERROR: relation "musicians" does not exist

  4. 4

    PG::UndefinedTable: ERROR: relation 'caves' does not exist

  5. 5

    rake aborted! PG::UndefinedTable: ERROR: relation "pages" does not exist

  6. 6

    rake aborted! PG::UndefinedTable: ERROR: relation "pages" does not exist

  7. 7

    ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "guestbooks" does not exist

  8. 8

    Table name as PostgreSQL function parameter / ERROR: column ".." does not exist

  9. 9

    ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "spree_orders" does not exist

  10. 10

    heroku postgresql database rails app PG::UndefinedTable: ERROR: relation "comments" does not exist

  11. 11

    PG::UndefinedTable: ERROR: relation "" does not exist - Amazon EC2, Postgresql, and Rails 5

  12. 12

    relation "table name" does not exist (postgresql)

  13. 13

    PGERROR: ERROR relation "table_name" does not exist (avoiding git commits)

  14. 14

    Rails PG::UndefinedTable: ERROR: missing FROM-clause entry for table

  15. 15

    PG::UndefinedTable: ERROR: missing FROM-clause entry for table

  16. 16

    PG::UndefinedTable: ERROR: missing FROM-clause entry for table

  17. 17

    Pg:Error column does not exist

  18. 18

    Heroku database error on production: PG::UndefinedTable Error

  19. 19

    Sidekiq PG::UndefinedColumn: ERROR: does not exist

  20. 20

    PG::UndefinedTable: ERROR: missing FROM-clause entry for table when using joins and where

  21. 21

    PG::UndefinedTable: ERROR: missing FROM-clause entry for table when using SELECT DISTINCT ON

  22. 22

    PG::UndefinedTable: ERROR: missing FROM-clause

  23. 23

    Bizarre PG::UndefinedTable Error with Rails app on Heroku

  24. 24

    PG::UndefinedTable ERROR ruby on rails heroku

  25. 25

    Heroku/Rails: PG:: Undefined Table: error "[tablename]" does not exist on heroku rails migration

  26. 26

    PHP pg_prepare() table name as parameter

  27. 27

    jdbc with embedded derby in javafx application: Table/View 'TABLE NAME' does not exist exception

  28. 28

    Rails 4: join queries with parent entity table, error: PG::UndefinedTable: ERROR: missing FROM-clause entry for table "states"

  29. 29

    A relation "table_name" does not exist in "Many2many relation" in Odoo 10.0

HotTag

Archive