Postgres on Rails FATAL: database does not exist

前提是你 提交于 2019-11-30 12:30:45

问题


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?


回答1:


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!




回答2:


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

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




回答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




回答4:


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!



来源:https://stackoverflow.com/questions/17933522/postgres-on-rails-fatal-database-does-not-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!