Model 作成メモ
開発環境
- pc:macOS Catalina 10.5.1
- ruby:2.6.3
- rails:6.0.1
migarat fileの作成
コマンド
rails g model モデル名(単数形) カラム名1:データ型 カラム名2:データ型2.....
migrate fileの確認
Path:root/db/migrate/...
class CreateBoards < ActiveRecord::Migration[6.0]
def change
create_table :boards do |t|
t.string :name
t.string :title
t.text :body
t.timestamps
end
end
end
migrate fileの実行
コマンド
rails db:migrate
migrate fileのキャンセル(roll back)
コマンド
rails db:rollback
migrateの実行前の状態に戻る。
もう一度rails db:migrate
を実行すると再度レコードの作成が実行される。