teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

マイグレーションファイルの追記

2017/06/18 00:16

投稿

riamk
riamk

スコア47

title CHANGED
File without changes
body CHANGED
@@ -60,4 +60,35 @@
60
60
  ```
61
61
 
62
62
  今はこのようにコードを書いています。
63
- 他に必要なコードがあれば記載しますので、ご教授よろしくお願いします。
63
+ 他に必要なコードがあれば記載しますので、ご教授よろしくお願いします。
64
+
65
+ ###補足・追記
66
+ `Messagesテーブルのマイグレーションファイル`
67
+ ```
68
+ class CreateMessages < ActiveRecord::Migration
69
+ def change
70
+ create_table :messages do |t|
71
+ t.text :body
72
+ t.references :conversation, index: true, foreign_key: true
73
+ t.references :user, index: true, foreign_key: true
74
+ t.boolean :read, default: false
75
+
76
+ t.timestamps null: false
77
+ end
78
+ end
79
+ end
80
+ ```
81
+
82
+ `Conversationsテーブルのマイグレーションファイル`
83
+ ```
84
+ class CreateConversations < ActiveRecord::Migration
85
+ def change
86
+ create_table :conversations do |t|
87
+ t.integer :sender_id
88
+ t.integer :recipient_id
89
+
90
+ t.timestamps null: false
91
+ end
92
+ end
93
+ end
94
+ ```