Rails 3 升級 Rails 4 中遇到的問題及解決方法

ericwu發表於2014-01-15

有些出現的問題其實是不懂正確的流程,都是在試錯,可是還是學到了很多東西,寫下了,希望對我和大家都有幫助。

Homebrew 的問題

當我去執行brew update的時候出現錯誤untracked working tree files,因為homebrew是用Git去更新的,所以如果目錄中出現untracked files就會導致不能更新。然後我看了homebrew的Common Issues文件

解決方法

其實我對Git還算了解,可是就不知道homebrew的working tree files在哪裡,所以下面的東西就直接解決了我的問題。

This is caused by an old bug in the update code that has long since been fixed. However, the nature of the bug requires that you do the following:

cd $(brew --repository)
git reset --hard FETCH_HEAD

If brew doctor still complains about uncommitted modifications, also run this command:

cd $(brew --repository)
git clean -fd

PostgreSQL 的問題

當出現pg gem不能bundle install的時候,我也嘗試過gem install pg -- --with-pg-config這種提示裡面的命令,可是還是不能解決這個問題。然後我就用homebrew把postgresql 從9.2.3升級到了9.3.2

後果

這樣做的直接後果就是postgresql不能正常啟動,出現了一下的提示資訊:

FATAL: database files are incompatible with server DETAIL: The data directory was initialized by PostgreSQL version 9.2, which is not compatible with this version 9.3.2.

原來postgresql升級以後不能相容原來的資料檔案,就是個悲劇啊。看了一下postgresql的升級文件,PostgreSQL major versions are represented by the first two digit groups of the version number,原來前兩位數字都是主版本號。

解決方法

一般自己機器上面的都是測試資料,所以可以直接刪除掉舊的資料庫檔案。執行一下命令就可以了。

rm -rf /usr/local/var/postgres
initdb -D /usr/local/var/postgres

如果你想要以前的資料檔案,特別如果遇到在production server上升級了postgresql,那麼你就需要使用pg_dump出原來的資料檔案,然後就要用到pg_upgrade啦。具體方式可以檢視pg_upgrade的文件。

Rails Gem PG 的問題

這個時候pg已經成功安裝成功了,可是在rake db:create的時候又出現關於postgresql的問題了:

Library not loaded: libpq.5.6.dylib

憑藉自己的經驗,覺得應該是postgresql中lib的這一個檔案沒有被rake的時候載入到。

解決方法

ln -s /usr/local/Cellar/postgresql/9.3.2/lib/libpq.5.6.dylib /usr/local/lib/libpq.5.6.dylib

然後就可以該幹嘛幹嘛了。

相關文章