Postgres on Rails FATAL:数据库不存在

时间:2022-01-21 00:16: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:

我重新安装了Postgres(9.2.4),但是我无法使用Rails 3.2.11进行备份。我做了:

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

我的database.yml文件看起来像

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:

当我运行rake db:create:all然后rake db:migrate我得到错误:

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").

我删除了schema.rb,seed.rb和迁移文件夹中的所有文件,以及我能想到的任何其他内容。但是,引用“帖子”的错误让我觉得我的先前数据库(有一个名为“帖子”的表)仍有一些旧的引用。

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

在尝试完全重新安装/刷新我的数据库时,是否有人知道如何解决此错误?

4 个解决方案

#1


54  

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!

我遇到了类似的问题。我检查了不同的网站,并尝试了他们的建议,但没有工作。然后我尝试了你的建议。 rake db:create:all和rake db:migrate它对我有用。谢谢!

#2


3  

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

您需要先创建数据库。运行rake db:create:all

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

还要确保为postgres正确设置了yml文件。

#3


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:

db:create:all和db:migrate首先对我不起作用。我在myapp / config / database.yml文件中将我的数据库名称从development.pg更改为developmentpg:

database: db/developmentpg

数据库:db / developmentpg

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

然后rake db:create:all和rake db:migrate,它对我有用。

Thank you

谢谢

#4


0  

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

我尝试运行rake db:create:all,这不起作用。但是,运行bundle exec rake db:create:all对我有用。

Hope this helps!

希望这可以帮助!

#1


54  

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!

我遇到了类似的问题。我检查了不同的网站,并尝试了他们的建议,但没有工作。然后我尝试了你的建议。 rake db:create:all和rake db:migrate它对我有用。谢谢!

#2


3  

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

您需要先创建数据库。运行rake db:create:all

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

还要确保为postgres正确设置了yml文件。

#3


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:

db:create:all和db:migrate首先对我不起作用。我在myapp / config / database.yml文件中将我的数据库名称从development.pg更改为developmentpg:

database: db/developmentpg

数据库:db / developmentpg

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

然后rake db:create:all和rake db:migrate,它对我有用。

Thank you

谢谢

#4


0  

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

我尝试运行rake db:create:all,这不起作用。但是,运行bundle exec rake db:create:all对我有用。

Hope this helps!

希望这可以帮助!