質問編集履歴

2

コード修正

2024/03/06 12:55

投稿

bokupiroki
bokupiroki

スコア54

test CHANGED
File without changes
test CHANGED
@@ -15,39 +15,7 @@
15
15
 
16
16
  Illuminate\Database\QueryException
17
17
 
18
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'created_at' in 'field list' (SQL: insert into `inquiries` (`inquiry_id`, `created_at`, `serial`, `customer`, `dealer`, `type`, `operator_id`, `questioner`, `phoneNumber`, `kinds`, `question`, `answer`, `satisfaction`, `remote`, `updated_at`, `created_at`) values (aaaaaa, 2023-03-19 00:00:00, 21555555, asdf, e, NASサーバー, 1, e, , 設定, 改行, 変更完了, 不満, TeamViewer, 2023-03-23 18:36:52, 2023-03-23 18:36:52))
19
18
 
20
- at vendor/laravel/framework/src/Illuminate/Database/Connection.php:703
21
- 699? // If an exception occurs when attempting to run a query, we'll format the error
22
- 700? // message to include the bindings with SQL, which will make this exception a
23
- 701? // lot more helpful to the developer instead of just the database's errors.
24
- 702? catch (Exception $e) {
25
- ? 703? throw new QueryException(
26
- 704? $query, $this->prepareBindings($bindings), $e
27
- 705? );
28
- 706? }
29
- 707? }
30
-
31
- ~ A column was not found: You might have forgotten to run your migrations. You can run your migrations using `php artisan migrate`.
32
- https://laravel.com/docs/master/migrations#running-migrations
33
-
34
- +18 vendor frames
35
- 19 database/seeders/InquiryTableSeeder.php:94
36
- Illuminate\Database\Eloquent\Model::__callStatic("updateOrCreate")
37
-
38
- +22 vendor frames
39
- 42 artisan:37
40
- Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
41
- ```
42
-
43
-
44
-
45
- ### 該当のソースコード
46
- ``cat backend/storage/app/private/csv/inquiries_migration.csv``でCSVファイルの中身を確認するとこうなっています。
47
- ```csv
48
- created_at,serial,customer,dealer,type,operator_id,questioner,phoneNumber,kinds,question,answer,satisfaction,inquiry_id,remote
49
- 2023-03-19 00:00:00,21555555,asdf,e,NASサーバー,1,e,,設定,改行,変更完了,不満,aaaaaa,TeamViewer
50
- ```
51
19
 
52
20
 
53
21
  ```php
@@ -92,24 +60,9 @@
92
60
  // 空白文字を含む可能性があるカラムの値から空白文字を削除
93
61
  $values['serial'] = trim($values['serial'] ?? '');
94
62
  $values['type'] = trim($values['type'] ?? '');
95
- $values['phoneNumber'] = trim($values['phoneNumber'] ?? '');
96
- $values['kinds'] = trim($values['kinds'] ?? '');
97
- $values['remote'] = trim($values['remote'] ?? '');
98
- $values['satisfaction'] = trim($values['satisfaction'] ?? '');
99
- $values['operator_id'] = trim($values['operator_id'] ?? '');
100
- $values['inquiry_id'] = trim($values['inquiry_id'] ?? '');
101
63
 
102
-
103
- // nullか空の場合は指定の値を代入する
64
+
104
- if (empty($values['kinds'])) {
65
+
105
- $values['kinds'] = '設定';
106
- }
107
- if (empty($values['remote'])) {
108
- $values['remote'] = 'なし';
109
- }
110
- if (empty($values['satisfaction'])) {
111
- $values['satisfaction'] = '満足';
112
- }
113
66
 
114
67
  if (isset($values['phoneNumber']) && !empty($values['phoneNumber'])) {
115
68
  $phoneNumberWithoutHyphen = preg_replace('/[^0-9]/', '', $values['phoneNumber']); // 数字以外の文字列を除去
@@ -147,8 +100,7 @@
147
100
 
148
101
 
149
102
  ### 試したこと
150
- phpMyAdminからinquiriesテーブルを確認すると、created_atカラムはあるように見えます。
103
+
151
- ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-03-23/49608456-af5a-40b4-b609-c34389e8207a.png)
152
104
 
153
105
  ``php artisan cache:clear``
154
106
  ``php artisan config:clear``
@@ -162,7 +114,7 @@
162
114
  YT0014さんより指摘があった通り、
163
115
 
164
116
  シーダー実行時のエラーに
165
- ``' created_at' in 'field list' (SQL: insert into `inquiries` (`inquiry_id`, `created_at`, `serial`, `customer`, `dealer`, `type`, `operator_id`, `questioner`, `phoneNumber`, `kinds`, `question`, `answer`, `satisfaction`, `remote`, `updated_at`, `created_at`)``とのエラーから、「created_at」が複数回指定されているようです。
117
+
166
118
 
167
119
  おそらく、csvファイル上に存在するcreated_atの値と、現在のタイムスタンプの両方を入力しようとしてしまっているのではないかと思います。
168
120
 

1

原因箇所を絞り込んだうえでの問題点を追記

2023/03/24 08:23

投稿

bokupiroki
bokupiroki

スコア54

test CHANGED
@@ -1 +1 @@
1
- シーダー読み込み時に、データベースに存在するはずカラムないかのようなエラーがで
1
+ シーダー読み込み時に、データベースにcreated_at登録処理2回走りエラーにな
test CHANGED
@@ -39,6 +39,8 @@
39
39
  42 artisan:37
40
40
  Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
41
41
  ```
42
+
43
+
42
44
 
43
45
  ### 該当のソースコード
44
46
  ``cat backend/storage/app/private/csv/inquiries_migration.csv``でCSVファイルの中身を確認するとこうなっています。
@@ -143,6 +145,7 @@
143
145
  }
144
146
  ```
145
147
 
148
+
146
149
  ### 試したこと
147
150
  phpMyAdminからinquiriesテーブルを確認すると、created_atカラムはあるように見えます。
148
151
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-03-23/49608456-af5a-40b4-b609-c34389e8207a.png)
@@ -155,6 +158,19 @@
155
158
  本番環境のubuntuの実機で同じことを行うとエラーになります。
156
159
  本番環境にはsshに入っています。
157
160
 
161
+ ### 追記
162
+ YT0014さんより指摘があった通り、
163
+
164
+ シーダー実行時のエラーに
165
+ ``' created_at' in 'field list' (SQL: insert into `inquiries` (`inquiry_id`, `created_at`, `serial`, `customer`, `dealer`, `type`, `operator_id`, `questioner`, `phoneNumber`, `kinds`, `question`, `answer`, `satisfaction`, `remote`, `updated_at`, `created_at`)``とのエラーから、「created_at」が複数回指定されているようです。
166
+
167
+ おそらく、csvファイル上に存在するcreated_atの値と、現在のタイムスタンプの両方を入力しようとしてしまっているのではないかと思います。
168
+
169
+ csvファイル上のcreated_atだけを使いたいのですが、何か方法はないでしょうか。
170
+
171
+ モデル側でタイムスタンプの自動挿入を無効にする方法もあるかとは思いますが、それだと影響範囲が大きいので別の方法があればありがたいです。
172
+
173
+
158
174
 
159
175
  ### 補足情報(FW/ツールのバージョンなど)
160
176
  Docker version 23.0.1, build a5ee5b1