0

我試圖刪除並重置我的數據庫在開發中:rake db:drop db:create db:migrate並且由於某種原因它沒有工作。現在,當我試圖運行命令,我得到:Rails無法重置開發數據庫

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/postgrespg_ctl start -D /usr/local/var/postgres,但無濟於事。

我在這一個完全停滯。任何人都知道如何重置數據庫並重新遷移?

+0

加入此聊天http://chat.stackoverflow.com/rooms/34391/http-stackoverflow-com-questions-17929808-rails-unable-to-reset-development-dat – rmagnum2002

回答

1

經過在postgres中的麻煩,事實證明這與數據庫模式或postgres無關。

我只需要註釋掉我的routes.rb文件,它引用了Post模型。隨着routes.rb註釋掉,我運行的遷移很好,然後取消註釋routes.rb。

+0

我會給你1000張票如果我可以。我的互聯網連接在db:pull中受到干擾,導致後續嘗試丟棄和重新開始時出現一些奇怪的postgres錯誤。就是這樣! – hellion