Rails 3 升级 Rails 4 中遇到的问题及解决方法

有些出现的问题其实是不懂正确的流程,都是在试错,可是还是学到了很多东西,写下了,希望对我和大家都有帮助。

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

然后就可以该干嘛干嘛了。

    原文作者:ericwu
    原文地址: https://segmentfault.com/a/1190000000388741
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞