sqlite3.DatabaseError:文件不是数据库 [英] sqlite3.DatabaseError: file is not a database

查看:54
本文介绍了sqlite3.DatabaseError:文件不是数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行以下INSERT语句时出现上述错误.数据库文件ce.db与我的代码位于同一目录中,并且我已经在其中成功创建了表.

I get the above error for executing the below INSERT-statement. The database file ce.db is in the same directory as my code and I have successfully created the tables therein.

我的sqlite版本是2.8.17,我确信我的db文件存在,因为我可以在目录中看到它,并且已经在其中成功创建了表.

My sqlite version is 2.8.17 and I am confident that my db file exists as I can see it in my directory and have succeeded in creating tables therein.

导入sqlite3

@app.route("/sign_up", methods=["GET", "POST"])
def sign_up():
  # [..other code..]

    conn = sqlite3.connect("ce.db")
    c = conn.cursor()
    result = c.execute("INSERT INTO users (name, hash) VALUES (:name, :hash)", {"name":request.form.get("username"), "hash":hashp})
    conn.commit()

对于以"result = ..."开头的行,调试器显示"sqlite3.DatabaseError:文件不是数据库"错误.

Debugger shows "sqlite3.DatabaseError: file is not a database" error for the line starting with "result=...".

推荐答案

进行了一些进一步的挖掘,结果发现2.6.0是DB-API版本(通过print(sqlite3.version)获得)-并不完全确定是或用于什么),而我的sqlite版本(print(sqlite3.sqlite_version))是3.22.0.还意识到(在bash中运行文件ce.db),我的ce.db是在2.x上创建的(或使用?).设法通过sqlite3 ce.db语句删除并重新创建了它.我知道所有初学者的问题,但认为与像我这样的未来迷失者分享这可能会有所帮助:)

Did some more digging and it turns out that 2.6.0 is the DB-API version (obtained via print(sqlite3.version) - not entirely sure what that is or what it's for) and my sqlite version (print(sqlite3.sqlite_version)) is 3.22.0. Also realised (running file ce.db in bash) that my ce.db was created on (or with?) 2.x... managed to remove and recreate it with sqlite3 ce.db statement.. seems to work now. All beginner problems, I know but figured it might helpt to share this for any future lost souls like me :)

这篇关于sqlite3.DatabaseError:文件不是数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆