Rails宝典八十三式:Migrations in Rails 2.0

Migrations are now sexy in Rails 2.0!

创建当前environme的数据库
rake db:create


创建所有environme的数据库
rake db:create:all


创建和修改Model
script/generate model task name:string priority:integer
script/generate migration add_description_to_task description:string
script/generate migration remove_description_from_task description:string


看看自动生成的migration文件
# migrations/001_create_tasks.rb
create_table :tasks do |t|
  t.string :name
  t.integer :priority, :position
  t.timestamps
end

# migrations/002_add_description_to_task.rb
add_column :tasks, :description, :text

# migrations/003_remove_description_from_task.rb
remove_column :tasks, :description

你可能感兴趣的:(Rails)