LoginSignup
0
0

More than 5 years have passed since last update.

初心者がRailsガイドを1から100まで読んでみる Railsをはじめよう編その5 マイグレーション

Last updated at Posted at 2018-09-22

5.5.マイグレーションを実行する

マイグレーションっていうのはRubyのクラスのひとつで、データベーステーブルの操作を簡単にするものなんだって。

タイムスタンプ_create_articles.rb
class CreateArticles < ActiveRecord::Migration[5.1]
  def change
    create_table :articles do |t|
      t.string :title
      t.text :text

      t.timestamps
    end
  end
end

changeっていうメソッドがあってその中でcreate_tableといういかにもテーブルを作ってくれそうな文が書いてある。
このファイル自体は今は特にいじる必要がなくて、以下のコマンドを打ってみよう。

$ bin/rails db:migrate
スクリーンショット 2018-09-21 17.53.52.png
なんかcreate_tableされたみたい。

これでテーブルができたようだ。
データを格納する先だね。
5章の最初に、ルーティングの設定にresources:articlesと追記してarticle関連のルートを一括で設定した。
今、そのarticleのデータを格納するテーブルができた。
役者が揃ってきた感じがするぞ。

その6
https://qiita.com/Natsuki_on_Rails/items/de9d80b2b44fee8ef2fb

0
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
0
0