I have a table in a database that is created and accessible through SQLAlchemy:
I add a record to it using Flask-SQLAlchemy, for example:
... content = request.form['content'] date = datetime.today() post = Post(date, content) db.session.add(post) db.session.commit() ...
This record is added to the table in order. Immediately after this code, I request another table:
userID = session['userID'] posts = db.session.query(Post).filter_by(userID=userID).count()
However, during the request, I get a message:
OperationalError: (raised as a result of a called Query autoflush; consider using the session.no_autoflush block if this flash happens prematurely) (_mysql_exceptions.OperationalError) (1292, "Date value is incorrect: '11 / 20 'for column" date "on row 1 ") [SQL: u'UPDATE messages SET date =% s WHERE posts.id =% s '] [parameters: (('11 / 20', 1L))]
Why is the date of adding a message updated when I already specified it when adding a record to the table? And what could be causing this error? Thanks.
Edit:
Here's what the table model looks like:
class Post(db.Model): __tablename__ = 'posts' id = db.Column(db.Integer, primary_key=True) content = db.Column(db.String(500)) date = db.Column(db.Date, nullable=False) def __init__(self, id, content, date): self.id = id self.content = content self.date = date
source share