class CreateBlogs < ActiveRecord::Migration
def self.up
create_table :blogs do |t|
t.references :role #连接的外键表
t.string :name, :limit => 40; #最在长度是40
t.decimal :length,:precision => 6, :scale => 2 #同于 decimal(6,2)
t.string :author, :default => 'Anonymous coward' #默认值是 Anonymous coward
t.timestamp :created_on
t.timestamp :updated_on
t.text :description
end
add_column "articles" :integer #添加列
end
def self.down
drop_table :blogs
remove_column "articles", "blog_id"
end
[b]问题补充:[/b]
自定义主键也就是说如登陆用的 userid 如果用userid 做主键 怎么做
create_table :blogs :primary_key => primaryId do |t| 怎么来定义它是字符串的