LoginSignup
0
1

More than 3 years have passed since last update.

データベース--メモ

Last updated at Posted at 2019-12-24

DBでよく使う型

string 文字列型
text テキスト(不定長文字列)型
integer 整数型
float 浮動小数点数型
decimal 固定長整数型
datetime 日時型
timestamp タイムスタンプ型
time 時刻型
date 日付型
binary バイナリ文字列型
boolean 真偽値型
references 他のテーブルへの外部キーの定義、_id が付いた整数

電話番号の型を設定するとき

integer型だと10桁まで。電話番号は11桁の時もある。なのでDBに登録できないことがある。
また、09012345678の場合、最初の0が消えることがある。
なので string型をおすすめします。
string型の文字列だとハイフン(ー)もDBに保存ができる

sample.rb
def change
    create_table :addresses do |t|
      t.references :user, foreign_key: true, null: false
      t.string  :post_code,          null: false
      t.string  :prefectures,        null: false
      t.string  :city,               null: false
      t.string  :address,            null: false
      t.string  :building_name
      t.string  :tel_no
      t.timestamps
    end
  end

参考記事

https://qiita.com/Yinaura/items/cede8324d08993d2065c
https://chinatz.hatenablog.com/entry/2018/07/20/210000

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