回答編集履歴

1

commentIdをユニークかつIntegerにする場合の改善点

2019/07/07 10:16

投稿

Kento75
Kento75

スコア65

test CHANGED
@@ -1 +1,23 @@
1
1
  commentIdがindex.js内に宣言されていないので、登録処理でエラーとなっています。
2
+
3
+
4
+
5
+ `commentId`をユニークキーに使用するのなら、`autoIncrement: true`の指定も必要だと思います。
6
+
7
+ `autoIncrement: true`を指定したカラムは、値を渡さなくても自動で採番してくれるので、登録処理のcommentIdの設定は不要となります。
8
+
9
+
10
+
11
+ ```
12
+
13
+ Comment.create({
14
+
15
+ comment:req.body.comment,
16
+
17
+ updatedAt: updatedAt
18
+
19
+
20
+
21
+ });
22
+
23
+ ```