Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PGError: ERROR: relation "table_name" does not exist

I am trying to push a simple app up to heroku and run:

heroku rake db:migrate

But I get the following error:

rake aborted!
PGError: ERROR:  relation "posts" does not exist
:             SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
              FROM pg_attribute a LEFT JOIN pg_attrdef d
                ON a.attrelid = d.adrelid AND a.attnum = d.adnum
             WHERE a.attrelid = '"posts"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum

Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)

My migration looks like this:

class CreatePosts < ActiveRecord::Migration
  def change
    create_table :posts do |t|
      t.string :source
      t.string :tweetid
      t.string :pure
      t.string :media
      t.string :destination
      t.datetime :time
      t.timestamps
    end
  end
end

And, after referring to another SO answer, I have included the following in my Gemfile:

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.1.4'
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'
  gem 'pg'
end

Thank you in advance for any help!

--- UPDATE ---

The main reason I am confused is that this all works locally, just not when I run the migration on heroku.

Here is the error I get now:

rake aborted!
Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.)

I have been looking at this question:

Heroku error when launch rails3.1 app missing postgres gem

I am almost-certain my database.yml should not look like this (seeing as I need to be running postgresql!!!):

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000

Serious apologies for the nubishness here. Thank you for your help in advance!

Also tried this link: Uploading to Heroku DB rake:migrate problem

like image 202
Richard Burton Avatar asked Dec 05 '11 22:12

Richard Burton


2 Answers

create_table :posts

Didn't you forget the s? The table names should be plural.

like image 100
Robin Avatar answered Oct 26 '22 09:10

Robin


I just ran: bundle exec rake db:migrate and it worked

like image 22
ajbraus Avatar answered Oct 26 '22 10:10

ajbraus