我正在尝试创建一个数据库来保存用户并攀登用户与用户完成攀爬的一对多关系。
class Climb(db.Model):
id = db.Column(db.Integer, primary_key=True)
date = db.Column(db.DateTime)
name = db.Column(db.String(64))
flash = db.Column(db.Boolean)
notes = db.Column(db.Text)
type_of_climb = db.Column(db.String(32))
difficulty = db.Column(db.String(5))
location = db.Column(db.String(64))
favorite = db.Column(db.Boolean)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
def __init__(self, climb_date, name, flash, notes, type_of_climb, difficulty, location, favorite, user_id):
set_date = datetime.strptime(climb_date, '%Y%m%d').date()
self.date = set_date
self.name = name
self.flash = flash
self.notes = notes
self.type_of_climb = type_of_climb
self.difficulty = difficulty
self.location = location
self.favorite = favorite
self.user_id = user_id
我正在尝试使用PyCharm中的Python控制台测试数据库。我已经成功创建了一个用户并且正在尝试向数据库添加爬升但是继续得到" TypeError:需要一个整数"当我使用以下命令集时:
>>> from flask import Flask
>>> from app import app, db
>>> db.create_all()
>>> from app import User, Climb
>>> c = Climb('2015-05-02', 'Climb so high', 1, 'Made it happen', 'Trad', '5.8', 'Nepal', 0, 1)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "<string>", line 4, in __init__
File "/home/logan/Desktop/DEV/git/Climb-On/climb-on-api/flask/local/lib/python2.7/site-packages/sqlalchemy/orm/state.py", line 269, in _initialize_instance
return manager.original_init(*mixed[1:], **kwargs)
File "/home/logan/Desktop/DEV/git/Climb-On/climb-on-api/app.py", line 50, in __init__
self.flash = flash
TypeError: an integer is required
我对如何得到错误完全感到困惑(flash是传递的第三个参数,我的帐号1是一个整数)。
非常感谢任何帮助。
答案 0 :(得分:0)
数据库中相应表的列可能不是SQLAlchemy所需的正确类型。