0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

①DB設計/モデル作成/中間テーブル

Last updated at Posted at 2018-04-28

①rails g model 単数形
削除の場合、rails d model 単数形

②マイグレーションファイルの変更

 型     説明     用例
 integer 数字     ユーザーのidなど
 string 文字(少なめ) ユーザー名、パスワードなど
 text  文字(多め) 投稿文など
 boolean 真か偽か 真偽フラグ
 datetime 日付と時刻 作成日時、更新日時など

 例:
class CreateTweets < ActiveRecord::Migration
 def change
  create_table :tweets do |t|
  t.string :name
 t.text :text
 t.text :image
 t.timestamps
 end
 end
 end
 
例2:中間テーブル
 class CreateEntries < ActiveRecord::Migration
def change
create_table :entries do |t|
t.references :user, index: true, foreign_key: true
t.references :job, index: true, foreign_key: true
t.timestamps
end
end
end

③マイグレーションファイルの実行
$ pwd

現在のディレクトリが正しいことを確認

$ rake db:migrate

マイグレーションファイルの実行

④データベースでデータを確認

④データベースを戻す場合
rake db:rollback
マイグレーションファイルの削除

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?