1
1対多の関係にある2つのモデルがあります。 お問い合わせ|| ------ o < - Specialneed複数のデータとの1対多の関係を挿入するsqlalchemyフラスコ
Flask SQLalchemyで構築された関係を使用して、Specialneedに複数のレコードを挿入したいと考えています。
applicationParams={
'startdate': request.form['startdate'],
'enddate': request.form['enddate'],
'starttime': request.form['starttime'],
'endtime': request.form['endtime'],
'budget': request.form['budget'],
'specialneed': [SpecialNeed(description=request.form['specialNeeds'])]}
をしかし、私はspecialneed'パラメータに」形式で入力されたspecialneedsのリストを与えるしようとすると、それは私にエラーを与える:
私はこのように、Specialneedに1つのレコードを挿入することができます
をapplicationParams={
'startdate': request.form['startdate'],
'enddate': request.form['enddate'],
'starttime': request.form['starttime'],
'endtime': request.form['endtime'],
'budget': request.form['budget'],
'specialneed': [SpecialNeed(description=[sn.strip() for sn in request.form['specialNeeds'].split('.')])]}
SQLのINSERT:私はそれを、それは私のコードでは、このようになりますリストを与える
(pymysql.err.InternalError) (1241, 'Operand should contain 1 column(s)')
[SQL: 'INSERT INTO specialneed (description, iid) VALUES
(%(description)s, %(iid)s)'] [parameters:
{'description': ['Speaks English', 'Can sing'], 'iid': 11}]
クエリは次のようになります。
SQL: 'INSERT INTO specialneed (description, iid) VALUES
(%(description)s, %(iid)s)'] [parameters:
{'description': 'Speaks English', 'iid': 11},
{'description': 'Can sing', 'iid': 11}]
これを管理するにはどうすればよいですか。