1
0

More than 3 years have passed since last update.

Rails model作成

Posted at

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 を実行すると再度レコードの作成が実行される。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0