Postgres on Rails 致命:数据库不存在 [英] Postgres on Rails FATAL: database does not exist
问题描述
我已经重新安装了 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
我已尝试清除与过去的数据库、迁移等相关的所有内容.
I have tried to clear out everything related to past db, migrations, etc.
我已经删除了 schema.rb、seed.rb 和迁移文件夹中的所有文件,以及我能想到的任何其他文件.但是提到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 on Rails 致命:数据库不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!