Postgres在Rails上致命:数据库不存在 [英] Postgres on Rails FATAL: database does not exist

查看:94
本文介绍了Postgres在Rails上致命:数据库不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经重新安装了Postgres(9.2.4),但无法在Rails 3.2.11中重新设置它。我做到了:

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

所以现在我有

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

我的database.yml文件看起来像

My database.yml file looks like

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

当我运行 rake db:create:all 然后 rake db:migrate 我收到错误消息:

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

我尝试清除

我已经删除了schema.rb,seed.rb和所有位于Migrations文件夹中的文件,以及其他所有内容可以想到的。但是有关 posts的错误使我认为仍然有一些旧的引用指向我以前的数据库(该数据库有一个名为 posts的表)。

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?

推荐答案

我遇到了类似的问题。
我检查了其他网站,并尝试了他们的建议,但是没有用。
然后我尝试了您的建议。
rake db:create:all rake db:migrate 对我有用。谢谢!

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!

这篇关于Postgres在Rails上致命:数据库不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆