【问题标题】:sqlite3.OperationalError: no such table: main.wordlist Errorsqlite3.OperationalError:没有这样的表:main.wordlist 错误
【发布时间】:2012-02-05 05:06:24
【问题描述】:

我基本上是在尝试创建一个新数据库并根据以下内容输入数据库值:

 def createindextables(self):
    self.con.execute('create table urllist(url)')
    self.con.execute('create table worldlist(word)')
    self.con.execute('create table wordlocation(urlid,wordid,location)')
    self.con.execute('create table link(fromid integer,toid integer)')
    self.con.execute('create table linkwords(wordid,linkid)')
    self.con.execute('create index wordidx on wordlist(word)')
    self.con.execute('create index urlidx on urllist(url)')
    self.con.execute('create index wordurlidx on wordlocation(wordid)')
    self.con.execute('create index urltoidx on link(toid)')
    self.con.execute('create index urlfromidx on link(fromid)')
    self.dbcommit()

但是在运行时出现“sqlite3.OperationalError: no such table: main.wordlist Error”。我不确定为什么它无法检测到搜索数据库。它至少应该从实时编译器运行。我不知道为什么它不能正常工作。有人可以帮忙吗?

【问题讨论】:

    标签: python


    【解决方案1】:

    可能是错字:worldlist 应该是 wordlist 吗? 如果是这样,将第二行更改为:

    self.con.execute('create table wordlist(word)')
    

    (否则,该行

    self.con.execute('create index wordidx on wordlist(word)')
    

    可能会引发错误,因为尚未定义 wordlist


    作为健全性检查,您可以尝试运行

    import sqlite3
    connection = sqlite3.connect(':memory:')
    cursor = connection.cursor()
    cursor.execute('create table urllist(url)')
    cursor.execute('create table wordlist(word)')
    

    这段代码应该可以工作。然后,您可以尝试比较此代码与您的不同之处。

    【讨论】:

    • 这就是我最初的想法,但我尝试了所有改进它的方法,它并没有真正奏效。我目前没有选择
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-10
    • 1970-01-01
    • 1970-01-01
    • 2017-05-16
    • 2015-07-30
    • 2016-02-20
    • 2018-08-18
    相关资源
    最近更新 更多