LoginSignup
1
1

More than 3 years have passed since last update.

マイグレーションファイル、カラムの「型」とは

Posted at

マイグレーションファイルは、テーブルの設計図・仕様書。db/migrate/20XXXXXXXXXXXX_create_XXXXX.rbのマイグレーションファイルを編集する。
create_table :posts do |t|
t.timestamps
の間にt.カラムの型 :カラムを必要なものを入れる
t.text :tite
t.string :text
t.text :image
など、、、
カラムの「型」は
|:-----|:-----|:-----|
| 型 | どのような型か | 用途 |
| integer | 数字 | 金額、回数など |
| string | 文字(短文) | ユーザー名、メールアドレスなど |
| text | 文字(長文) | 投稿文など |
| boolean | 真か偽か | はい・いいえの選択肢など |
| datetime | 日付と時刻 | 作成日時、更新日時など |
を参考にして記述する。
このままではデータベースにテーブルを作成はまだできてないので、ターミナルでrails db:migrateを実行する。Sequel Proでテーブルを作成できていればテーブルの完成

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