Postgres on Rails FATAL: database does not exist
Solution 1
You need to create the databases first. Run rake db:create:all
Also make sure your yml file is set up correctly for postgres.
Solution 2
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
-
Tyler about 4 years
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
thenrake 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?