質問編集履歴
1
デザインを見やすくした。
test
CHANGED
File without changes
|
test
CHANGED
@@ -9,6 +9,8 @@
|
|
9
9
|
データベースですが、Categoryというクラスにカテゴリーの情報を、Detailというクラスにお金を使用したときの情報を入れておきたいと考えています。また、これら二つのクラスをカテゴリ名を用いて一対多リレーションシップとしてデータベースを作成したいと考えています。
|
10
10
|
|
11
11
|
こちらがflask-sqlalchemyの公式ドキュメントのDeclearing Modelsのone to many relationshipを参考に作ったデータベースです。
|
12
|
+
|
13
|
+
```python
|
12
14
|
class Category(db.Model):
|
13
15
|
name = db.Column(db.String,db.ForeignKey('name'),primary_key=True)
|
14
16
|
budget = db.Column(db.Integer,nullable=False)
|
@@ -22,6 +24,8 @@
|
|
22
24
|
purchased_item = db.Column(db.String,nullable=False)
|
23
25
|
date = db.Column(db.String,nullable=False)
|
24
26
|
|
27
|
+
```
|
28
|
+
|
25
29
|
こちらを実行すると出てきたエラー文がこちらです。
|
26
30
|
sqlalchemy.exc.NoForeignKeysError: Could not determine join condition between parent/child tables on relationship Detail.name - there are no foreign keys linking these tables. Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression.
|
27
31
|
|
@@ -29,7 +33,7 @@
|
|
29
33
|
なぜこのエラーが起きているのか、そしてその対応策を教えていただきたいです。
|
30
34
|
|
31
35
|
pythonのコード
|
32
|
-
|
36
|
+
```python
|
33
37
|
from flask import Flask
|
34
38
|
from flask import render_template,redirect,request,session
|
35
39
|
from flask_sqlalchemy import SQLAlchemy
|
@@ -88,3 +92,5 @@
|
|
88
92
|
db.session.add(add_detail)
|
89
93
|
db.session.commit()
|
90
94
|
|
95
|
+
```
|
96
|
+
|