我收到以下错误:
sqlalchemy.exc.StatementError :( exceptions.TypeError)SQLite DateTime type仅接受Python日期时间和日期对象作为输入。
尝试在dvdrelease
列中插入以下日期时间实例时:
'dvdrelease': datetime.datetime(2015, 11, 3, 0, 53, 32, 682000)
我在后台使用Arrow做一些字符串解析,而arrow正在返回上面代码中的值(value = datetime.datetime(2015, 11, 3, 0, 53, 32, 682000)
)
箭头代码示例:(收到的字符串始终遵循以下格式:&#34; 1月3日和34日;&#34; 12月22日&#34;,&#34; 6月3日和#34 ;.)< / p>
#!venv/bin/python
import arrow
import time
import datetime
# arrow string parsing
def string_to_date(y):
''' Takes a MON d (Jan 3) string and converts it into a full date and time '''
# get current times
time_now = arrow.utcnow()
this_year = str(time_now.year)
this_hour = str(time_now.hour)
this_minute = str(time_now.minute)
this_second = str(time_now.second)
this_milli = str(time_now.microsecond)
time.sleep(0.1) # sleep so the microseconds variables never match
full_time = y + " " + this_year + " " + this_hour + " " + this_minute + " " + this_second + " " + this_milli
final_output = arrow.get(full_time, 'MMM D YYYY H m ss SSS').naive
return final_output
但是为什么SQLite说这不是一个有效的插入?
了解它的价值,这里是如何在我的models.py
文件(Flask网络应用程序)中定义此列:
dvdrelease = db.Column(db.DateTime, index=True)
我在插入之前对变量做了type()
:
Nov 3
<type 'unicode'>
2015-11-03 01:26:48.389000
<type 'datetime.datetime'>