Hello, I have a small webapp using flask and sqlAlchemy.
Im currently stuck at one problem. The problem is that I can not remove entries from the database using sqlAlchemy. The error wich gets returned:
sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) NOT NULL constraint failed: attachment.share_id
[SQL: UPDATE attachment SET share_id=? WHERE attachment."ID" = ?]
[parameters: (None, 1)]
(Background on this error at: http:
What my codes looks like (the sql module):
class Share(db.Model):
ID = db.Column(db.Integer, primary_key=True)
id = db.synonym("ID")
uuid = db.Column(db.String(36), unique=True,
nullable=False, default=get_unique_id)
title = db.Column(db.String(100), nullable=True)
content = db.Column(db.Text, nullable=False)
date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
user_id = db.Column(db.Integer, db.ForeignKey('user.ID'), nullable=False)
attachments = db.relationship(
"Attachment", backref="share", lazy=True)
comments = db.relationship(
"Comment", backref="share", order_by="desc(webapp.models.Comment.date)", lazy=True)
def __repr__(self):
return f"<Share('{self.ID}', '{self.title}', '{self.date}')>"
The code where I try to remove the entry:
@app.route("/community/share/<share_uuid>/delete")
@login_required
def delete_share(share_uuid):
share = Share.query.filter_by(uuid=share_uuid).first()
if share and share.author == current_user:
pass
else:
abort(403)
if request.args.get("confirm") == "yes":
db.session.delete(share)
db.session.commit()
flash("Share successfully deleted.", "flash")
return redirect(url_for('community'))
return render_template("community/share/delete.html", share=share, title="Delete Share?")
What I have tried:
I have no Idea where to start so please send me some help...