パンくずリスト
書籍 RailsによるアジャイルWebアプリケーション開発
カラムの変更とmigrate
概要
カラムの変更とmigrate
詳細
マイグレーションファイルを編集し、以下のコマンドを実行することでDBを最新の状態に変更できます。
変更前のマイグレーションファイル
class CreateProducts < ActiveRecord::Migration def change create_table :products do |t| t.string :title t.text :description t.string :image_url t.decimal :price, presision: 8, scale: 2 t.timestamps end end end
変更後のマイグレーションファイル
class CreateProducts < ActiveRecord::Migration def change create_table :products do |t| t.string :title t.text :description t.string :image_url t.decimal :price t.timestamps end end end
変更の実施
rake db:migrate
実行時コンソール内容
== CreateProducts: migrating ================================================= -- create_table(:products) -> 0.0010s == CreateProducts: migrated (0.0020s) ========================================