python interfaceerror -1_错误消息:InterfaceError:<unprintable InterfaceError object>

在尝试使用SQLAlchemy连接两个表并创建包含外键的窗体时遇到问题,引发了`sqlalchemy.exc.InterfaceError`。错误表现为无法打印的InterfaceError对象。代码中定义了`Client`和`Stand`两个数据库模型,它们之间存在一对多关系。在`newstand`路由的POST请求处理函数中,当表单验证通过后,尝试添加新的`Stand`实例到数据库时,错误发生。寻求关于这个问题的解决方案或建议。
摘要由CSDN通过智能技术生成

将两个表链接在一起并尝试创建一个包含外键的窗体。在

在sqlalchemy.exc.InterfaceError在

InterfaceError:无法打印的InterfaceError对象

数据库链接完成方式:class Client(db.Model):

__tablename__ = 'Client'

..

stand_id = db.Column(db.String(10), index = True, unique = True)

stands = db.relationship('Stand', backref= 'Stand', lazy='select')

def __init__(self,client_name,contact_number,contact_name,contact_email,stand_id):

self.client_name = client_name

self.contact_number = contact_number

self.contact_email = contact_email

self.contact_name = contact_name

self.stand_id = stand_id

class Stand(db.Model):

__tablename__ = 'Stand'

..

stand_number = db.Column(db.String(10), db.ForeignKey('Client.stand_id' ))

def __repr__(self):

return '' % (self.stand_id)

def __init__(self, stand_name,items, quantity,install_date,

derig_date,comments,last_update, stand_number):

self.stand_name = stand_name

self.items = items

self.quantity = quantity

self.install_date = install_date

self.derig_date = derig_date

self.comments = comments

self.last_update = last_update

self.stand_number = stand_number

形式为

^{pr2}$

并将其视为@app.route('/newstand', methods = ['GET','POST'])

def newstand():

form = StandForm()

if form.validate():

stand = Stand(

request.form['stand_name'], request.form['items'], request.form['quantity'],

request.form['install_date'],request.form['derig_date'], request.form['comments'],

request.form['last_update'], request.form['stand_number'])

form.populate_obj(stand)

db.session.add(stand)

db.session.commit()

return render_template('liststands.html',

stand = stand,

form=form)

else:

flash("Your form contained errors")

return render_template('newstand.html', form = form

我觉得我写的函数不太正确,有什么意见/帮助吗?在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值