執行rake db:migrate時的兩個錯誤

來源:互聯網
上載者:User

        rails的確是來的方便,一個rails generate scaffold命令下來就可以產生view、controller和model的所有檔案,然後再執行rake db:migrate就可以產生相應的資料庫表結構。而就是這個簡單的rake db:migrate卻產生了預想不到的問題:

         首先交代一下背景:rails建立項目時,預設使用了SQLite資料庫。為了快速上手,我換成了MySQL,也修改了相應的設定檔config/database.yml。

         第一個問題:

                 rake aborted!

                 uninitialized constant Rake:DSL

        原因:預設安裝的rake版本過低,不相容

        解決辦法:升級rake

        步驟:1. 安裝0.9.2版本的rake,gem install rake -version=0.9.2

                     2. 卸載原來版本(可以通過gem -list rake查看當前安裝的版本), gem uninstall rake -version=0.8.7

                     3. 更新所有組件,bundle update

         4.運行 rake db:migrate。於是出現第二個問題。


   第二個問題:

         rake aborted。

         Mysql::Error: query: not connected: SHOW TABLES

   原因:MySQL5.1內建的libmySQL.dll和當前的rails不相容

   解決辦法:使用舊版本替換。

   步驟:1. 下載舊版本的libmySQL.dll: http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/libmySQL.dll

        2. 將下載的檔案放到%RUBY_HOME/bin目錄下。

 

   參考:

   http://stackoverflow.com/questions/6085610/rails-rake-problems-uninitialized-constant-rakedsl

       http://rordiary.com/blog/tag/mysql/

   

    

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.