精華區beta Ruby 關於我們 聯絡資訊
出自我的Blog http://lightyror.blogspot.com/2006/09/migration-console.html Migration 一般來說 要寫 migrate 的 file 然後打 rake migrate 有沒有辦法可以直接在 console 裡面直接操作 Migration 也就是用 console mode 直接做 DB admin 我常說 Rails 什麼都有,什麼都賣,什麼都不奇怪 所以一定有辦法 XD 1. 進入 Console Mode ruby script/console 2. 進入 AR 環境 irb ActiveRecord::Base.connection 這樣就OK啦,我們可以在console環境下 新增 table ,刪除 table ,看 table 的 column 之類的 以下簡單的操作法 checks 有多少 table tables check 某個 table 的 column columns('table_name').each { |c| puts c.name } columns('table_name').each { |c| puts c.name+' -> '+c.type.to_s } 新增 table,這裡用 Migration File 寫比較好 create_table "abc", :force => true do |t| t.column "lala", :integer, :limit => 30, :default => 0, :null => false end drop table drop_table :table_name -- lighty RoR 是一個介紹 lighttpd , SQLite , Ruby and Rails 的 Blog http://lightyror.blogspot.com/ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.218.90.242