質問編集履歴
2
文章修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,89 +1,33 @@
|
|
1
1
|
現在Rails on Rubyに取り組んでいるのですが、
|
2
2
|
下記のエラーが解決できません。
|
3
3
|
|
4
|
-
StandardError: An error has occurred, this and all later migrations canceled:
|
5
4
|
|
6
|
-
undefined local variable or method `introduction' for #<AddIntroductionToUsers
|
7
|
-
|
8
|
-
|
9
5
|
ことの発端は現在作成しているアプリの
|
10
|
-
ブラウザ上でユーザー情報のintroductionを更新すると何故か時間が表示され、スキーマを確認したところ
|
6
|
+
ブラウザ上でユーザー情報のintroductionを更新すると何故か時間が表示され、スキーマを確認したところdatetimeとなっておりました。(本来はstringにしたい)
|
11
|
-
変更だけすればよかったものの、
|
7
|
+
変更だけすればよかったものの、まずはintroductionのdatetimeの定義を消そうと思い、
|
12
|
-
|
8
|
+
下記migrateファイルを作成しました。
|
13
9
|
|
14
10
|
|
15
|
-
①間違った処理を元に戻したい
|
16
|
-
②introdukutionのdatetimeをtextに変更したい
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
どなたか助けていただけると大変幸いです。
|
21
|
-
|
22
|
-
|
23
|
-
以下行った処理↓
|
24
|
-
*間違ったコマンドでusersが何故か入れてしまっております…
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
`20210926125504_add_introduction_to_users.rb`
|
29
|
-
class AddRememberCreatedAtToUsers < ActiveRecord::Migration[5.2]
|
30
|
-
def change
|
31
|
-
remove_column :users, introduction, :datetime
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
`20210926141718_remove_introduction_from_users`
|
37
|
-
class AddIntroductionToUsers < ActiveRecord::Migration[5.2]
|
38
|
-
def change
|
39
|
-
add_column :users, introduction, :text
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
↑と同じ処理のファイルがもう一つ存在しています。
|
44
|
-
|
45
11
|
`20210924164709_add_remember_created_at_to_users`
|
12
|
+
```
|
46
|
-
class AddRememberCreatedAtToUsers < ActiveRecord::Migration[5.2]
|
13
|
+
class AddRememberCreatedAtToUsers < ActiveRecord::Migration[5.2]
|
47
14
|
def change
|
48
15
|
remove_column :users, introduction, :datetime
|
49
16
|
end
|
50
17
|
end
|
51
18
|
|
19
|
+
```
|
52
20
|
|
21
|
+
現在上記ファイルはstatusで確認するとup状態です。
|
22
|
+
ここからエラーが出てしまうようになり、
|
23
|
+
一度今回作成してしまったdatetime削除用のmigrateファイルをdown状態にしようとコマンドを入力すると、以下のエラーが出てきます。
|
53
24
|
|
25
|
+
SQLite3::SQLException: duplicate column name: introduction: ALTER TABLE "users" ADD "introduction" datetime
|
54
26
|
|
55
|
-
また、introductionとは関係なく、処理の途中でWebサイトからコピペしたものを変更しないまま貼り付け→処理を行なってしまい、
|
56
|
-
|
27
|
+
Caused by:
|
28
|
+
ActiveRecord::StatementInvalid: SQLite3::SQLException: duplicate column name: introduction: ALTER TABLE "users" ADD "introduction" datetime
|
57
29
|
|
58
|
-
class RemoveAuthorFromTitles < ActiveRecord::Migration[5.2]
|
59
|
-
def change
|
60
|
-
remove_column :titles, :author, :string
|
61
|
-
end
|
62
|
-
end
|
63
30
|
|
31
|
+
上記、調べるとカラムかテーブルが重複しているとのことなのですが、
|
64
|
-
|
32
|
+
何をしていけば良いのかが分からず行き詰まってしまい・・・
|
65
|
-
class AddDetailsToTitles < ActiveRecord::Migration[5.2]
|
66
|
-
def change
|
67
|
-
add_column :titles, :price, :integer
|
68
|
-
add_column :titles, :author, :string
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
|
33
|
+
ご助力頂けると大変幸いです。
|
74
|
-
|
75
|
-
`schema.rb`
|
76
|
-
create_table "users", force: :cascade do |t|
|
77
|
-
t.string "email", default: "", null: false
|
78
|
-
t.string "encrypted_password", default: "", null: false
|
79
|
-
t.string "reset_password_token"
|
80
|
-
t.datetime "reset_password_sent_at"
|
81
|
-
t.datetime "remember_created_at"
|
82
|
-
t.string "name"
|
83
|
-
t.datetime "created_at", null: false
|
84
|
-
t.datetime "updated_at", null: false
|
85
|
-
t.string "profile_image_id"
|
86
|
-
t.text "introduction"
|
87
|
-
t.index ["email"], name: "index_users_on_email", unique: true
|
88
|
-
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
89
|
-
end
|
1
スキーマの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -67,4 +67,23 @@
|
|
67
67
|
add_column :titles, :price, :integer
|
68
68
|
add_column :titles, :author, :string
|
69
69
|
end
|
70
|
-
end
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
また現在のスキーマです。
|
74
|
+
|
75
|
+
`schema.rb`
|
76
|
+
create_table "users", force: :cascade do |t|
|
77
|
+
t.string "email", default: "", null: false
|
78
|
+
t.string "encrypted_password", default: "", null: false
|
79
|
+
t.string "reset_password_token"
|
80
|
+
t.datetime "reset_password_sent_at"
|
81
|
+
t.datetime "remember_created_at"
|
82
|
+
t.string "name"
|
83
|
+
t.datetime "created_at", null: false
|
84
|
+
t.datetime "updated_at", null: false
|
85
|
+
t.string "profile_image_id"
|
86
|
+
t.text "introduction"
|
87
|
+
t.index ["email"], name: "index_users_on_email", unique: true
|
88
|
+
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
89
|
+
end
|