質問編集履歴

2

マイグレーションファイルの追加

2019/11/08 05:22

投稿

kurotaku6
kurotaku6

スコア8

test CHANGED
File without changes
test CHANGED
@@ -81,3 +81,345 @@
81
81
  DB_PASSWORD=<パスワード>
82
82
 
83
83
  ```
84
+
85
+
86
+
87
+ マイグレーション対象ファイルは以下です。
88
+
89
+ ```
90
+
91
+ <?php
92
+
93
+
94
+
95
+ use Illuminate\Support\Facades\Schema;
96
+
97
+ use Illuminate\Database\Schema\Blueprint;
98
+
99
+ use Illuminate\Database\Migrations\Migration;
100
+
101
+
102
+
103
+ class CreateUsersTable extends Migration
104
+
105
+ {
106
+
107
+ /**
108
+
109
+ * Run the migrations.
110
+
111
+ *
112
+
113
+ * @return void
114
+
115
+ */
116
+
117
+ public function up()
118
+
119
+ {
120
+
121
+ Schema::create('users', function (Blueprint $table) {
122
+
123
+ $table->increments('id');
124
+
125
+ $table->string('name');
126
+
127
+ $table->integer('stance')->default(1);
128
+
129
+ $table->integer('board')->default(1);
130
+
131
+ $table->string('introduction')->nullable();
132
+
133
+ $table->string('image_path')->nullable();
134
+
135
+ $table->string('email')->unique();
136
+
137
+ $table->timestamp('email_verified_at')->nullable();
138
+
139
+ $table->string('password');
140
+
141
+ $table->rememberToken();
142
+
143
+ $table->timestamps();
144
+
145
+ });
146
+
147
+ }
148
+
149
+
150
+
151
+ /**
152
+
153
+ * Reverse the migrations.
154
+
155
+ *
156
+
157
+ * @return void
158
+
159
+ */
160
+
161
+ public function down()
162
+
163
+ {
164
+
165
+ Schema::dropIfExists('users');
166
+
167
+ }
168
+
169
+ }
170
+
171
+ ```
172
+
173
+ ```ここに言語を入力
174
+
175
+ <?php
176
+
177
+
178
+
179
+ use Illuminate\Support\Facades\Schema;
180
+
181
+ use Illuminate\Database\Schema\Blueprint;
182
+
183
+ use Illuminate\Database\Migrations\Migration;
184
+
185
+
186
+
187
+ class CreateSpotsTable extends Migration
188
+
189
+ {
190
+
191
+ /**
192
+
193
+ * Run the migrations.
194
+
195
+ *
196
+
197
+ * @return void
198
+
199
+ */
200
+
201
+ public function up()
202
+
203
+ {
204
+
205
+ Schema::create('spots', function (Blueprint $table) {
206
+
207
+ $table->increments('id');
208
+
209
+ $table->integer('user_id')->unsigned();
210
+
211
+ $table->string('name');
212
+
213
+ $table->string('place');
214
+
215
+ $table->string('body');
216
+
217
+ $table->timestamps();
218
+
219
+
220
+
221
+ // 外部キーを設定する
222
+
223
+ $table->foreign('user_id')->references('id')->on('users');
224
+
225
+ });
226
+
227
+ }
228
+
229
+
230
+
231
+ /**
232
+
233
+ * Reverse the migrations.
234
+
235
+ *
236
+
237
+ * @return void
238
+
239
+ */
240
+
241
+ public function down()
242
+
243
+ {
244
+
245
+ Schema::dropIfExists('spots');
246
+
247
+ }
248
+
249
+ }
250
+
251
+ ```
252
+
253
+ ```ここに言語を入力
254
+
255
+ <?php
256
+
257
+
258
+
259
+ use Illuminate\Support\Facades\Schema;
260
+
261
+ use Illuminate\Database\Schema\Blueprint;
262
+
263
+ use Illuminate\Database\Migrations\Migration;
264
+
265
+
266
+
267
+ class CreateDiariesTable extends Migration
268
+
269
+ {
270
+
271
+ /**
272
+
273
+ * Run the migrations.
274
+
275
+ *
276
+
277
+ * @return void
278
+
279
+ */
280
+
281
+ public function up()
282
+
283
+ {
284
+
285
+ Schema::create('diaries', function (Blueprint $table) {
286
+
287
+ $table->increments('id');
288
+
289
+ $table->integer('spot_id')->unsigned();
290
+
291
+ $table->integer('user_id')->unsigned();
292
+
293
+ $table->string('title');
294
+
295
+ $table->integer('score');
296
+
297
+ $table->integer('condition');
298
+
299
+ $table->integer('size');
300
+
301
+ $table->string('body');
302
+
303
+ $table->string('image_path')->nullable();
304
+
305
+ $table->timestamps();
306
+
307
+
308
+
309
+ // 外部キー設定
310
+
311
+ $table->foreign('spot_id')->references('id')->on('spots');
312
+
313
+ $table->foreign('user_id')->references('id')->on('users');
314
+
315
+ });
316
+
317
+ }
318
+
319
+
320
+
321
+ /**
322
+
323
+ * Reverse the migrations.
324
+
325
+ *
326
+
327
+ * @return void
328
+
329
+ */
330
+
331
+ public function down()
332
+
333
+ {
334
+
335
+ Schema::dropIfExists('diaries');
336
+
337
+ }
338
+
339
+ }
340
+
341
+
342
+
343
+ ```
344
+
345
+ ```ここに言語を入力
346
+
347
+ <?php
348
+
349
+
350
+
351
+ use Illuminate\Support\Facades\Schema;
352
+
353
+ use Illuminate\Database\Schema\Blueprint;
354
+
355
+ use Illuminate\Database\Migrations\Migration;
356
+
357
+
358
+
359
+ class CreateCommentsTable extends Migration
360
+
361
+ {
362
+
363
+ /**
364
+
365
+ * Run the migrations.
366
+
367
+ *
368
+
369
+ * @return void
370
+
371
+ */
372
+
373
+ public function up()
374
+
375
+ {
376
+
377
+ Schema::create('comments', function (Blueprint $table) {
378
+
379
+ $table->increments('id');
380
+
381
+ $table->integer('user_id')->unsigned();
382
+
383
+ $table->integer('diary_id')->unsigned();
384
+
385
+ $table->string('body');
386
+
387
+ $table->timestamps();
388
+
389
+
390
+
391
+ //外部キー
392
+
393
+ $table->foreign('user_id')->references('id')->on('users');
394
+
395
+ $table->foreign('diary_id')->references('id')->on('diaries');
396
+
397
+ });
398
+
399
+ }
400
+
401
+
402
+
403
+ /**
404
+
405
+ * Reverse the migrations.
406
+
407
+ *
408
+
409
+ * @return void
410
+
411
+ */
412
+
413
+ public function down()
414
+
415
+ {
416
+
417
+ Schema::dropIfExists('comments');
418
+
419
+ }
420
+
421
+ }
422
+
423
+
424
+
425
+ ```

1

envの追加

2019/11/08 05:22

投稿

kurotaku6
kurotaku6

スコア8

test CHANGED
File without changes
test CHANGED
@@ -61,3 +61,23 @@
61
61
  と表示され実行できません。
62
62
 
63
63
  unix_socketあたりが問題なのでしょうか?
64
+
65
+
66
+
67
+ .envは以下で設定しています。
68
+
69
+ ```env
70
+
71
+ DB_CONNECTION=mysql
72
+
73
+ DB_HOST=<エンドポイント>
74
+
75
+ DB_PORT=3306
76
+
77
+ DB_DATABASE=
78
+
79
+ DB_USERNAME=<マスターユーザー名>
80
+
81
+ DB_PASSWORD=<パスワード>
82
+
83
+ ```