Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

既存のmodelにカラムを追加する

$ rails g migration add_column_#{カラム名アンダーバー区切り}_to_#{テーブル名} カラム名スネークケース:テーブル名

という形で追加します。

実例を上げると

$ rails g migration add_column_business_state_to_companies businessState:integer
      invoke  active_record
      create    db/migrate/2014xxxxxxxxxx_add_column_business_state_to_companies.rb

となります。
これでrake db:migrateすると、現状のカラムが修正されます。
seedの更新をお忘れなく。

デフォの開発環境であればsqlite3コマンドで確認可能です。

$ sqlite3 db/development.sqlite3 
SQLite version 3.7.13 2012-07-17 17:46:21
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .schema funds
CREATE TABLE "companies" ("id" ...(中略)..., "businessState" integer);