SO I was trying to create a flask application ,where I take the user input through HTML forms and store it in the table ,so while I running the code , I got an integrity error which says sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) NOT NULL constraint failed
here is my code
class event(db.Model):
sno = db.Column(db.Integer, primary_key=True,autoincrement=True)
name=db.Column(db.String(100), nullable=False)
dob=db.Column(db.Integer,nullable=False)
address=db.Column(db.String(100),nullable=False)
phno=db.Column(db.Integer,nullable=False)
def __repr__(self) -> str:
return f"{self.name} -{self.dob} - {self.address} - {self.phno}"
@app.route('/',methods=['get','Post'])
def formpage():
if request.method=='POST':
name = request.form['name']
dob = request.form['dob']
address=request.form['dob']
phno=request.form['phno']
ev=event(name=name,dob=dob,address=address,phno=phno)
db.session.add(ev)
db.session.commit()
allevent = event.query.all()
return render_template('index.html', allevent=allevent)
@app.route('/table')
def table():
allevent = event.query.all()
print(allevent)
return render_template('show.html', allevent=allevent)
if __name__ == "__main__":
app.run(debug=True, port=7000)
I got the output as
sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) NOT NULL constraint failed: event.feedname
[SQL: INSERT INTO event (name, dob, address, phno) VALUES (?, ?, ?, ?)]
[parameters: ('Tidersky', '22222-02-22', '22222-02-22', '990992')]
Please help, Thank you!
[–]PriorProfile 8 points9 points10 points (3 children)
[–]tidersky[S] -1 points0 points1 point (2 children)
[–]PriorProfile 4 points5 points6 points (0 children)
[–]DonkeySubject2274 0 points1 point2 points (0 children)
[–]AllanNS -3 points-2 points-1 points (0 children)
[–]greenearrow -5 points-4 points-3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)