41

I've reinstalled Postgres (9.2.4) and I'm having trouble getting it set back up with Rails 3.2.11. I did:

brew install postgresql
initdb /usr/local/var/postgres
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

So now I have

$ psql --version
psql (PostgreSQL) 9.2.4
$ which psql
/usr/local/bin/psql

My database.yml file looks like

development:
  adapter: postgresql
  encoding: unicode
  database: myapp_development
  pool: 5
  username: Tyler
  password:
  host: localhost
  port: 5432

And when I run rake db:create:all then rake db:migrate I get the error:

PG::Error: ERROR:  relation "posts" does not exist
LINE 5:              WHERE a.attrelid = '"posts"'::regclass
                                    ^
:         SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                 pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
          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

I have tried to clear out everything related to past db, migrations, etc.

I've deleted the schema.rb, seed.rb, and all files in the migrations folder, and anything else I can think of. But the error referring to "posts" makes me think there is still some old reference to my prior database (which had a table called "posts").

Does anyone know how to troubleshoot this error, when trying to completely reinstall/refresh my database?

4
  • This sounds like your migration files are not consistent. Are you sure you are creating posts before referencing it? Commented Jul 29, 2013 at 20:30
  • I tried putting only the first migration file in the migration folder (which does not reference posts anywhere), and I still get the problem. I also tried removing ALL migration files, and I still get the message... Commented Jul 29, 2013 at 20:31
  • Does rake db:drop:all help? Commented Jul 29, 2013 at 20:33
  • Are you trying to access the database at the class level in any of your models? Commented Jul 29, 2013 at 20:33

4 Answers 4

83

I was having a similar problem. I checked different websites and tried what they suggested but didn't work. Then I tried what you suggested. rake db:create:all and rake db:migrate it worked for me. Thank you!

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

1 Comment

this wasn't working for me until I adde bundle exec. bundle exec rake db:create:all. Thanks!
4

You need to create the databases first. Run rake db:create:all

Also make sure your yml file is set up correctly for postgres.

Comments

3

db:create:all and db:migrate did not work for me first. I changed my database name from development.pg to developmentpg in myapp/config/database.yml file:

database: db/developmentpg

and then rake db:create:all and rake db:migrate, it worked for me.

Thank you

Comments

0

I tried running rake db:create:all, which didn't work. However, running bundle exec rake db:create:all worked for me.

Hope this helps!

Comments

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.