質問編集履歴

2

文章修正

2021/09/27 06:17

投稿

kurazira
kurazira

スコア2

test CHANGED
File without changes
test CHANGED
@@ -1,14 +1,6 @@
1
1
  現在Rails on Rubyに取り組んでいるのですが、
2
2
 
3
3
  下記のエラーが解決できません。
4
-
5
-
6
-
7
- StandardError: An error has occurred, this and all later migrations canceled:
8
-
9
-
10
-
11
- undefined local variable or method `introduction' for #<AddIntroductionToUsers
12
4
 
13
5
 
14
6
 
@@ -16,45 +8,21 @@
16
8
 
17
9
  ことの発端は現在作成しているアプリの
18
10
 
19
- ブラウザ上でユーザー情報のintroductionを更新すると何故か時間が表示され、スキーマを確認したところtextではなくdatetimeとなっておりました。
11
+ ブラウザ上でユーザー情報のintroductionを更新すると何故か時間が表示され、スキーマを確認したところdatetimeとなっておりました。(本来はstringにしたい)
20
12
 
21
- 変更だけすればよかったものの、間違った方法でmigrateファイルを消したり作ったりしてしまってかなりmigrateファイルをいじってしまい行き詰まってしまいました…。
13
+ 変更だけすればよかったものの、まずはintroductionのdatetimeの定義消そうと思
22
14
 
23
- とめると以下の通りです
15
+ 下記migrateファイルを作成しした
24
16
 
25
17
 
26
18
 
27
19
 
28
20
 
29
- ①間違った処理を元に戻したい
21
+ `20210924164709_add_remember_created_at_to_users`
30
22
 
31
- ②introdukutionのdatetimeをtextに変更したい
23
+ ```
32
24
 
33
-
34
-
35
-
36
-
37
-
38
-
39
- どなたか助けていただけると大変幸いです。
40
-
41
-
42
-
43
-
44
-
45
- 以下行った処理↓
46
-
47
- *間違ったコマンドでusersが何故か入れてしまっております…
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
- `20210926125504_add_introduction_to_users.rb`
56
-
57
- class AddRememberCreatedAtToUsers < ActiveRecord::Migration[5.2]
25
+ class AddRememberCreatedAtToUsers < ActiveRecord::Migration[5.2]
58
26
 
59
27
  def change
60
28
 
@@ -66,112 +34,32 @@
66
34
 
67
35
 
68
36
 
69
-
70
-
71
- `20210926141718_remove_introduction_from_users`
72
-
73
- class AddIntroductionToUsers < ActiveRecord::Migration[5.2]
74
-
75
- def change
76
-
77
- add_column :users, introduction, :text
78
-
79
- end
37
+ ```
80
-
81
- end
82
38
 
83
39
 
84
40
 
85
- ↑と同じ処理のファイルがもう一つ存在しています。
41
+ 現在上記ファイルはstatusで確認るとup状態です
42
+
43
+ ここからエラーが出てしまうようになり、
44
+
45
+ 一度今回作成してしまったdatetime削除用のmigrateファイルをdown状態にしようとコマンドを入力すると、以下のエラーが出てきます。
86
46
 
87
47
 
88
48
 
89
- `20210924164709_add_remember_created_at_to_users`
49
+ SQLite3::SQLException: duplicate column name: introduction: ALTER TABLE "users" ADD "introduction" datetime
90
50
 
91
- class AddRememberCreatedAtToUsers < ActiveRecord::Migration[5.2]
92
51
 
93
- def change
94
52
 
95
- remove_column :users, introduction, :datetime
53
+ Caused by:
96
54
 
97
- end
55
+ ActiveRecord::StatementInvalid: SQLite3::SQLException: duplicate column name: introduction: ALTER TABLE "users" ADD "introduction" datetime
98
-
99
- end
100
56
 
101
57
 
102
58
 
103
59
 
104
60
 
61
+ 上記、調べるとカラムかテーブルが重複しているとのことなのですが、
105
62
 
63
+ 何をしていけば良いのかが分からず行き詰まってしまい・・・
106
64
 
107
-
108
-
109
- また、introductionとは関係なく、処理の途中でWebサイトからコピペしたものを変更しないまま貼り付け→処理を行なってしまい、
110
-
111
- 以下となっております。
112
-
113
-
114
-
115
- class RemoveAuthorFromTitles < ActiveRecord::Migration[5.2]
116
-
117
- def change
118
-
119
- remove_column :titles, :author, :string
120
-
121
- end
122
-
123
- end
124
-
125
-
126
-
127
- ↑誤って関係のないタイトルを消してしまい、以下に追加し直しました。
128
-
129
- class AddDetailsToTitles < ActiveRecord::Migration[5.2]
130
-
131
- def change
132
-
133
- add_column :titles, :price, :integer
134
-
135
- add_column :titles, :author, :string
136
-
137
- end
138
-
139
- end
140
-
141
-
142
-
143
-
144
-
145
- また現在のスキーマです。
65
+ ご助力頂けると大変幸いです。
146
-
147
-
148
-
149
- `schema.rb`
150
-
151
- create_table "users", force: :cascade do |t|
152
-
153
- t.string "email", default: "", null: false
154
-
155
- t.string "encrypted_password", default: "", null: false
156
-
157
- t.string "reset_password_token"
158
-
159
- t.datetime "reset_password_sent_at"
160
-
161
- t.datetime "remember_created_at"
162
-
163
- t.string "name"
164
-
165
- t.datetime "created_at", null: false
166
-
167
- t.datetime "updated_at", null: false
168
-
169
- t.string "profile_image_id"
170
-
171
- t.text "introduction"
172
-
173
- t.index ["email"], name: "index_users_on_email", unique: true
174
-
175
- t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
176
-
177
- end

1

スキーマの追加

2021/09/27 06:17

投稿

kurazira
kurazira

スコア2

test CHANGED
File without changes
test CHANGED
@@ -137,3 +137,41 @@
137
137
  end
138
138
 
139
139
  end
140
+
141
+
142
+
143
+
144
+
145
+ また現在のスキーマです。
146
+
147
+
148
+
149
+ `schema.rb`
150
+
151
+ create_table "users", force: :cascade do |t|
152
+
153
+ t.string "email", default: "", null: false
154
+
155
+ t.string "encrypted_password", default: "", null: false
156
+
157
+ t.string "reset_password_token"
158
+
159
+ t.datetime "reset_password_sent_at"
160
+
161
+ t.datetime "remember_created_at"
162
+
163
+ t.string "name"
164
+
165
+ t.datetime "created_at", null: false
166
+
167
+ t.datetime "updated_at", null: false
168
+
169
+ t.string "profile_image_id"
170
+
171
+ t.text "introduction"
172
+
173
+ t.index ["email"], name: "index_users_on_email", unique: true
174
+
175
+ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
176
+
177
+ end