質問編集履歴
3
書式改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -64,7 +64,17 @@
|
|
64
64
|
|
65
65
|
|
66
66
|
|
67
|
-
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
68
78
|
|
69
79
|
|
70
80
|
|
2
試してみたこと、変更したソースコードの更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
laravel でタグ機能を実装しようとしたのですが、テーブル作成後マイグレーションファイルをいじったら下記のエラーが出てしまい詰まってます。
|
1
|
+
laravel 7 でタグ機能を実装しようとしたのですが、テーブル作成後マイグレーションファイルをいじったら下記のエラーが出てしまい詰まってます。
|
2
2
|
|
3
3
|
|
4
4
|
|
@@ -65,3 +65,25 @@
|
|
65
65
|
|
66
66
|
|
67
67
|
よろしくお願いします。
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
<<追記
|
72
|
+
|
73
|
+
ご指摘のとおり、マイグレーションファイルの順番が正しい順になっていなかったので、一度マイグレーションファィルを手動で削除した後、再度作り直すと
|
74
|
+
|
75
|
+
```
|
76
|
+
|
77
|
+
SQLSTATE[HY000]: General error: 3780 Referencing column 'tag_id' and referenced column 'id' in foreign key constraint 'title_tag_tag_id_foreign' are incompatible. (SQL: alter table `title_tag` add constraint `title_tag_tag_id_foreign` foreign key (`tag_id`) references `tags` (`id`) on delete cascade)
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
このようなエラーに変わりました。
|
82
|
+
|
83
|
+
・試したこと
|
84
|
+
|
85
|
+
それぞれのIDのところをデフォルトの$table->id();に変えて migration refresh → php artisan migrateしてみましたがだめでした。
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
紐付けたいIDの型が違うとこのようなエラーが出るらしいのですが、それぞれの型はbigint unsigned 連番 で揃っていました。
|
1
migrationファイル を変更しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
Schema::create('tags', function (Blueprint $table) {
|
22
22
|
|
23
|
-
$table->i
|
23
|
+
$table->id();
|
24
24
|
|
25
25
|
$table->timestamps();
|
26
26
|
|
@@ -44,7 +44,7 @@
|
|
44
44
|
|
45
45
|
Schema::create('title_tag', function (Blueprint $table) {
|
46
46
|
|
47
|
-
$table->i
|
47
|
+
$table->id();
|
48
48
|
|
49
49
|
$table->timestamps();
|
50
50
|
|