1

我试图在开发中删除并重置我的数据库:rake db:drop db:create db:migrate但由于某种原因它没有工作。现在,当我尝试运行该命令时,我得到:

FATAL:  database "myapp_development" does not exist
FATAL:  database "myapp_test" does not exist
ERROR:  relation "posts" does not exist at character 315
STATEMENT:              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

如果我只尝试rake db:create db:migrate然后我得到错误

myapp_development already exists
myapp_test already exists
ERROR:  relation "posts" does not exist at character 315...

如果我只运行,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

我尝试重新启动我的数据库:pg_ctl stop -D /usr/local/var/postgres pg_ctl start -D /usr/local/var/postgres,但无济于事。

我在这个完全停滞不前。有人知道如何重置数据库并重新迁移吗?

4

1 回答 1

1

在 postgres 经历了很多麻烦之后,事实证明这与数据库模式或 postgres 无关。

我只需要注释掉引用 Post 模型的 routes.rb 文件。注释掉 routes.rb 后,我运行迁移就好了,然后取消注释 routes.rb。

于 2013-07-29T21:54:30.887 回答