0
0

More than 3 years have passed since last update.

Ruby on Rails テーブル作成手順

Posted at

Ruby on Railsでテーブルを作成する方法を記述します。

1:マイグレーションファイル作成

テーブルの設計図であるマイグレーションファイルを生成します。

テーブル名
User

カラム一覧

カラム名 データ形
id integer
name string
password string
created_at datetime
updated_at datetime
console
rails g model User name:string password:string

*id、crated_at、updated_atは自動的に作られるので記述しない

作成されたマイグレーションファイルは、
db ⇨ migrateフォルダ内に、「(年月日時分秒)createモデル名(複数形).rb」として生成されています。

2:マイグレーションファイルを反映させる

作成したマイグレーションファイルをデータベースに適用させます。

console
rails db:migrate

以上でテーブルを生成することができます。

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