-1
我想插入數據到燒瓶postgresql數據庫。如何插入數據到postgresql數據庫與瓶 - sqlalchemy.exc.ProgrammingError?
這是我寫的模型類代碼。
class Bet365(db.Model):
__tablename__ = "bet365s"
id = db.Column(db.Integer, primary_key=True)
sports = db.Column(db.Float)
casino = db.Column(db.Float)
poker = db.Column(db.Float)
games_bingo = db.Column(db.Float)
total = db.Column(db.Float)
withdrawal = db.Column(db.Float)
balance = db.Column(db.Float)
def __init__(self, sports, casino, poker, games_bingo, total, withdrawal, balance):
self.id = id
self.sports = sports
self.casino = casino
self.poker = poker
self.games_bingo = games_bingo
self.total = total
self.withdrawal = withdrawal
self.balance = balance
這是代碼段,其負責插入數據。
@app.route('/testing/')
def testing():
data_bet365 = bet365_scrapping()
sports = float(data_bet365[0])
casino = float(data_bet365[1])
poker = float(data_bet365[2])
games_bingo = float(data_bet365[3])
total = float(data_bet365[4])
withdrawal = float(data_bet365[5])
balance = float(data_bet365[6])
result_bet365 = Bet365(sports, casino, poker, games_bingo, total, withdrawal, balance)
db.session.add(result_bet365)
db.session.commit()
return (jsonify(data_bet365))
當我運行這個腳本時,出現這樣的錯誤。
sqlalchemy.exc.ProgrammingError
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'builtin_function_or_method'
[SQL: 'INSERT INTO bet365s (id, sports, casino, poker, games_bingo, total, withdrawal, balance) VALUES (%(id)s, %(sports)s, %(casino)s, %(poker)s, %(games_bingo)s, %(total)s, %(withdrawal)s, %(balance)s)']
[parameters: {'withdrawal': 0.0, 'id': <built-in function id>, 'sports': -29.94, 'total': 593.75, 'casino': 464.22, 'poker': 14.29, 'games_bingo': 145.17, 'balance': 593.75}]
我找不到解決方案。請幫幫我。
感謝您的回覆。請再看一遍。我已經更新了我的問題。對不起,打擾你。 –
啊,它看起來像你試圖插入一個空值到ID列。哪個應該是自動生成的字段。 –