As a beginner, code like:
class Message(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(20), nullable=False)
content = db.Column(db.Text, nullable=False)
timestamp = db.Column(db.String(20), nullable=False)
And I open Flask Shell, m = Message(name=’L’, content=’db.test’, timestamp=’2024-08-14 12:17:30′)
However, when I code db.session.commite()
sqlalchemy.exc.StatementError: (builtins.TypeError) SQLite DateTime type only accepts Python datetime and date objects as input.
[SQL: INSERT INTO message (name, content, timestamp) VALUES (?, ?, ?)]
[parameters: [{'timestamp': '2024-08-14 12:17:30', 'content': 'db.test', 'name': 'L'}]]
This is my problem,
find error, what should I do
moyu Lua is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
I just change ‘timestamp’ as ‘time’
>>> from app import Message
>>> m = Message(name='L', content='like', time='246800')
>>> m.time
>>> '246800'
>>> db.session.add(m)
>>> db.session.commit()
This right!
I don’t know the rationale behind it. Is it a special name?
moyu Lua is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.