sqlite3.操作错误:没有这个表:main.wordlist错误

0 投票
1 回答
2302 浏览
提问于 2025-04-17 12:20

我基本上是想创建一个新的数据库,并根据以下内容输入数据库的值:

 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”的错误。我不太明白为什么它无法找到这个搜索数据库。它至少应该在实时编译器中运行。我不知道为什么它不正常工作。有人能帮忙吗?

1 个回答

0

这可能是个打字错误: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)')

这段代码应该能正常工作。然后你可以对比一下这段代码和你的代码有什么不同。

撰写回答