Rails2.1新特性之新的migrations方法change_table

原文:http://blog.codefront.net/2008/05/04/living-on-the-edge-of-rails-19-change_table-for-migrations-and-more/

现在可以通过 change_table 代码块来完成对数据库表的修改。

change_table :videos do |t|
 t.add_timestamps
 t.add_belongs_to :goat
 t.add_string :name, :email, :limit => 20
 t.remove_column :name, :email # takes multiple arguments
 t.rename :new_name
 t.string :new_string_column # executes against the renamed table name
end

补充些要注意的事情:

* add_XXX 方法会添加一个新列,比如 add_string 会添加一个新的 string 类型的字段。
* Of course, add_timestamps 会添加神奇的 created_at 和 updated_at 的 datetime 类型的字段。
* remove_column 现在可以接受多个参数。
* rename 方法会重命名数据库表。

This entry was posted on 星期一, 05月 12th, 2008 at 11:43 pm and is filed under Ruby. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

没有评论

Be the first to comment on this entry.

Have your say

You must be logged in to post a comment.

Recent Posts:
  1. Blog已搬迁 - 2008-08-22
  2. a few interesting rails plugin - 2008-08-06
  3. Get Start Java Network App Dev - 2008-08-06
  4. 思考着Blog搬家 - 2008-07-28
  5. a bug in attachment_fu - 2008-07-28
  1. 我的梦想

    我的梦想是成为世界级的软件开发者。。。 联系我请mailto: chenk85 AT gmail.com 或者加我MSN: chenk85 AT live.cn
  2. 标签

  3.  

    05月 2008
    « Apr   Jun »
     123
    45678910
    11121314151617
    18192021222324
    25262728293031
  4. 文章分类

  5. 存档页

  6. 评头论足

    • 功能