質問編集履歴

4

rails db:migrate:statu修正

2019/10/21 22:23

投稿

menmanegi_ayaka
menmanegi_ayaka

スコア10

test CHANGED
File without changes
test CHANGED
@@ -146,24 +146,30 @@
146
146
 
147
147
  ```
148
148
 
149
- $rails db:migarte:status の結果です
149
+ $rails db:migrate:status の結果です
150
150
 
151
151
  ```
152
152
 
153
- rails aborted!
153
+ database: taskleaf_development
154
154
 
155
- Don't know how to build task 'db:migarte:status' (See the list of available tasks with `rails --tasks`)
156
155
 
157
- Did you mean? db:migrate:status
158
156
 
159
- /Users/mymac/study/taskleaf/bin/rails:9:in `<top (required)>'
157
+ Status Migration ID Migration Name
160
158
 
161
- /Users/mymac/study/taskleaf/bin/spring:15:in `<top (required)>'
159
+ --------------------------------------------------
162
160
 
163
- bin/rails:3:in `load'
161
+ up 20191017095612 Create tasks
164
162
 
165
- bin/rails:3:in `<main>'
163
+ up 20191019012825 Rename descriprion column to tasks
166
164
 
167
- (See full trace by running task with --trace)
165
+ up 20191020005240 Change tasks name not null
166
+
167
+ up 20191020005913 Change task name limit30
168
+
169
+ up 20191020023534 Create users
170
+
171
+ up 20191020025503 Add admin to users
172
+
173
+ down 20191020071103 Add user id to tasks
168
174
 
169
175
  ```

3

マイグレーションファイル修正

2019/10/21 22:23

投稿

menmanegi_ayaka
menmanegi_ayaka

スコア10

test CHANGED
File without changes
test CHANGED
@@ -92,11 +92,35 @@
92
92
 
93
93
 
94
94
 
95
- 10/22/22:40 追記
95
+ 追記
96
96
 
97
97
 
98
98
 
99
- migrationファイルです
99
+ migrationファイルです(downの最初です)
100
+
101
+ ```
102
+
103
+ class ChangeTaskNameLimit30 < ActiveRecord::Migration[6.0]
104
+
105
+ def up
106
+
107
+ change_column :tasks, :name, :string, limit:30
108
+
109
+ end
110
+
111
+ def down
112
+
113
+ change_column :tasks, :name, :string
114
+
115
+ end
116
+
117
+ end
118
+
119
+ ```
120
+
121
+
122
+
123
+ migrationファイルです(念の為downの2つ目です)
100
124
 
101
125
  ```
102
126
 

2

rails db:migarte:status追記

2019/10/20 13:48

投稿

menmanegi_ayaka
menmanegi_ayaka

スコア10

test CHANGED
File without changes
test CHANGED
@@ -19,6 +19,8 @@
19
19
  `bundle exec rake db:migrate`
20
20
 
21
21
  をしてみたのですが、ターミナルでこのようなメッセージが出ました。
22
+
23
+
22
24
 
23
25
 
24
26
 
@@ -92,6 +94,10 @@
92
94
 
93
95
  10/22/22:40 追記
94
96
 
97
+
98
+
99
+ migrationファイルです
100
+
95
101
  ```
96
102
 
97
103
  class AddUserIdToTasks < ActiveRecord::Migration[6.0]
@@ -115,3 +121,25 @@
115
121
  end
116
122
 
117
123
  ```
124
+
125
+ $rails db:migarte:status の結果です
126
+
127
+ ```
128
+
129
+ rails aborted!
130
+
131
+ Don't know how to build task 'db:migarte:status' (See the list of available tasks with `rails --tasks`)
132
+
133
+ Did you mean? db:migrate:status
134
+
135
+ /Users/mymac/study/taskleaf/bin/rails:9:in `<top (required)>'
136
+
137
+ /Users/mymac/study/taskleaf/bin/spring:15:in `<top (required)>'
138
+
139
+ bin/rails:3:in `load'
140
+
141
+ bin/rails:3:in `<main>'
142
+
143
+ (See full trace by running task with --trace)
144
+
145
+ ```

1

コード追記

2019/10/20 13:45

投稿

menmanegi_ayaka
menmanegi_ayaka

スコア10

test CHANGED
File without changes
test CHANGED
@@ -87,3 +87,31 @@
87
87
 
88
88
 
89
89
  教えて頂けると助かります。よろしくお願いいたします。
90
+
91
+
92
+
93
+ 10/22/22:40 追記
94
+
95
+ ```
96
+
97
+ class AddUserIdToTasks < ActiveRecord::Migration[6.0]
98
+
99
+ def up
100
+
101
+ execute 'DELLETE FROM tasks;'
102
+
103
+ add_reference :tasks, :user, null: false, index: true
104
+
105
+ end
106
+
107
+
108
+
109
+ def down
110
+
111
+ remove_reference :tasks, :user, index: true
112
+
113
+ end
114
+
115
+ end
116
+
117
+ ```