zasman
zasman

Reputation: 486

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

My app works fine in production, but when I move to production and run 'heroku run rake db:migrate', I get the following error:

    PG::UndefinedTable: ERROR:  table "applications" does not exist
    Migrating to DropApplications (20160509013805)
        (0.8ms)  BEGIN
    == 20160509013805 DropApplications: migrating             =================================
    -- drop_table(:applications)
       (1.1ms)  DROP TABLE "applications"
        (0.5ms)  ROLLBACK
    rake aborted!
     StandardError: An error has occurred, this and all later migrations    canceled:

     PG::UndefinedTable: ERROR:  table "applications" does not exist
   : DROP TABLE "applications"

However, there IS an 'applications' table in my database. The drop perhaps has something to do with when I dropped and then remade the applications scaffold the other day. How do I fix this?

      create_table "applications", force: :cascade do |t|
t.string   "name"
t.string   "gender"
t.date     "date_of_birth"
t.string   "gpa"
t.text     "essay"
t.datetime "created_at",    null: false
t.datetime "updated_at",    null: false
      end

So when I run run rake:db setup, I see the following results:

      Status   Migration ID    Migration Name
    --------------------------------------------------
       up     20160505200754  ********** NO FILE **********
       up     20160508234634  Create users
      up     20160508234945  Add devise to users
       up     20160509013805  ********** NO FILE **********
       up     20160509014328  ********** NO FILE **********
        20160509014911  Create applications

The two before "create applications" I attempted to delete. So, I try to rake the heroku db like so: $ heroku run rake --trace db:migrate VERSION=20151127134901 but I still get the error with the "drop tables"- its trying to do the 20160509013805 migrations. How do I delete those migrations completely where it says no file so it doesn't try to rake those too? Thank you in advance.

Upvotes: 3

Views: 3065

Answers (3)

Tom Haywood
Tom Haywood

Reputation: 21

I had this issue but all I had to do was run heroku run rake db:migrate because I had changed my database since the last time I pushed to Heroku.

Upvotes: 0

uday
uday

Reputation: 8710

Resetting heroku db:

Heroku doesn't allow to drop db. Instead you should be doing heroku pg:reset. This commands needs you to specify the DATABASE which can be found by heroku pg:info, then you will get an output like below:

=== DATABASE_URL
Plan:        Hobby-dev
Status:      Available
Connections: 0/20
PG Version:  9.4.4
Created:     2015-10-11 23:14 UTC
Data Size:   6.7 MB
Tables:      5
Rows:        0/10000 (In compliance)
Fork/Follow: Unsupported
Rollback:    Unsupported
Add-on:      postgresql-cubed-1838

Once you get the output like above use the heroku pg:reset command with appending the "Add-on" field value. Example I would be doing this:

$ heroku pg:reset postgresql-cubed-1838

Upvotes: 2

Yimanei
Yimanei

Reputation: 242

There might be a problem in your migration files. If you deleted one but another corresponding file remains, it can cause this error. I would have commented but I don't have the reputation yet.

Upvotes: 5

Related Questions