繁体   English   中英

表X没有名为Y的列(Python)

[英]Table X has no column named Y (Python)

这是较长的Python程序的数据库处理部分:

dbcon = lite.connect('spcbase.db')  # Connects to database file spcbase.db.
cur=dbcon.cursor()                  # Creates database cursor.
cur.execute("CREATE TABLE IF NOT EXISTS spectrum(spectrumID INTEGER PRIMARY KEY AUTOINCREMENT, seriesID INTEGER, scan_ang DECIMAL, Path TEXT)")
cur.execute("CREATE TABLE IF NOT EXISTS series(seriesID INTEGER PRIMARY KEY AUTOINCREMENT, date DATE, gpsx DECIMAL, gpsy DECIMAL, colprec DECIMAL, refangle DECIMAL)")
    # Executes SQL-query that will create one table of spectrums
    # and one table over series of measurements, should these
    # tables or this database not exist.
with dbcon:
    cur.execute("INSERT INTO series(date, gpsx, gpsy, colprec, refangle) VALUES(CURRENT_DATE, ?, ?, ?, ?)", [AP[0], AP[1], 6, refangle])
cur.execute("SELECT MAX(seriesID) FROM series")
current_series = cur.fetchone()[0]
src = u'.\\MaestroData'
dest = u'.\\target'
files=getspc(src)
i=0
for mfile in files:
    oldpath=os.path.normpath(os.path.join(src,mfile))
    print "oldpath: ", oldpath
    newpath=os.path.normpath(os.path.join(dest,mfile))
    print "newpath", newpath
    os.rename(oldpath,newpath)
    with dbcon:
        cur.execute("INSERT INTO spectrum(seriesID, scan_ang, Path) VALUES (?, ?, ?)", [current_series, scan_dirs[i], newpath])
    i=i+1
dbcon.close()

运行时,尽管仅在上面几行声明了这样的列,但仍收到错误“操作错误:表频谱没有列scan_ang”。 怎么了?

您忘记提交:

dbcon.commit()

只有这样,所有修改查询才会真正发生。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM