1

I've pushed my app to Heroku and now am trying to run '$ heroku rake db:migrate'. I get this error:

PGError: ERROR: relation "inventories" does not exist : SELECT "inventories".* FROM "inventories"

On my local machine everything works great. The local is using SQLite 3. Also, previous versions of the app worked just fine -- the previous versions did include the inventories model. Now, I've read ( almost ) every post on stackoverflow and on the web about this issue, but I still cannot find a way around it. Does anybody have any advice on getting this to work?

Ruby 1.9.2 ROR 3

UPDATE.. Here is the source to the migration that creates the inventories table:

class CreateInventories < ActiveRecord::Migration
  def self.up
    create_table :inventories do |t|
      t.decimal :initial_amount, :precision => 10, :scale => 2
      t.decimal :remaining_amount, :precision => 10, :scale => 2
      t.string :unit
      t.decimal :cost, :precision => 10, :scale => 2
      t.integer :type_id
      t.integer :brand_id
      t.integer :blend_id
      t.integer :user_id
      t.boolean :in

      t.timestamps
    end
  end

  def self.down
    drop_table :inventories
  end
end
2
  • Your table name is for sure "inventories" and not "inventory?" Commented Nov 23, 2010 at 14:35
  • Yep, here it is in the schema: create_table "inventories", :force => true do |t| Commented Nov 23, 2010 at 16:00

3 Answers 3

1

Have you used the Inventory model in your migration? Maybe you have an error in your migration, for example you edited the migration file after you migrated your local database?

In any case, running rake --trace db:migrate should show you the whole error message, together with stack trace - you will find the problematic line of code.

UPDATE:

In your stack trace (link is in the comment) there is one suspicious line:

...0-d4e1268c8981/mnt/config/environment.rb:5

What code is there?

Sign up to request clarification or add additional context in comments.

4 Comments

Here is what the trace looks like: pastie.org/private/keoyrgixjf6sdv7gy8tfqa . Unfortuanatly, I don't see that it gives me a line or even a specific file where the error is.
What is in the 5th line of your config/environment.rb ?
FIP::Application.initialize! This app was based off another app I had been working on. Seems like this may need to be updated. I'll try updating and let you know.
You may also try to comment out this line for the time of migration. Maybe this will fix the problem?
1

SOLUTION: I finally figured out the issue. I had this method in my user model:

def self.search( id )
  @inventory = Inventory.where(:primary_user [id])
  @cups = Cup.where(:user_id [id])

  @inventory + @cups
end

For some reason, that caused errors. I updated it to use @user.inventories and @user.cups instead. Thanks everybody.

Comments

1

The error indicates that the table does not exist remotely. See this: http://docs.heroku.com/database#common-issues-migrating-to-postgresql

I would expect a previous db:migrate to have created the table, unless database changes have occurred outside of the rake db task. I find that it's rather easy to get this out of sync. You can run specific migrations by specifying the migration method desired (up or down) and the timestamp of the migration to be executed. An example:

heroku rake db:migrate:up VERSION=20101108092153

This runs the migration generated on 11/8/2010 at 9:21:53 AM. You can browse your migrations in the db/ folder to find the migration that contains the missing table.

7 Comments

Thanks for explaining how to use the versions. I ran that line on a few different versions, but still got the same error. I pasted the error in a comment above. I read the article you referenced and tried running ActiveRecord::Base.connection.tables to see if the table had been created. I got an error saying it was an invalid command. Any ideas on how to debug this? Thanks.
Is this the first time you've migrated on Heroku? If so, are you using Postgres locally?
No and yes. I had the app on Heroku but destroyed it and tried from scratch. I got the same error when the app had been migrated before and I got the error on the brand new app. I am using sqlite 3 locally.
Could you add the source of the failing migration to the question?
Added the source for the migration i think is failing ( its the on that creates the inventories table )
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.