数据库错误:sql 上的执行失败:没有这样的表:联赛 [英] DatabaseError: Execution failed on sql : no such table: League
问题描述
我正在尝试使用 python 连接到 sqllite3 数据库.错误是:
I am trying to connect to the sqllite3 database using python. The error is:
DatabaseError: Execution failed on sql 'SELECT * FROM League':
no such table: League
Python 代码:
import sqlite3
import os.path
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
from sklearn.cluster import KMeans
from sklearn.preprocessing import scale
#BASE_DIR = os.path.dirname(os.path.abspath(pat))
#database = os.path.join(BASE_DIR, "database.sqlite")
#with sqlite3.connect(database) as conn:
#
# print("Connection Successful",conn)
# df = pd.read_sql_query("SELECT * FROM Country", conn)
pat = r'C:\Users\pouru\Downloads\soccer'
database = pat + 'database.sqlite'
conn = sqlite3.connect(database)
print("Connection Successful",conn)
df = pd.read_sql_query('SELECT * FROM League', conn)
它说连接成功,但是当我插入最后一条语句以获取表数据时,它会产生上述错误.我尝试使用绝对路径方式解决它,就像我上面评论的代码一样,但它给出了相同的错误.
It says connection successful but when I insert the last statement to get the table data, it produces the above error. I tried to solve it using the absolute path way like the code I have commented above but it gives the same error.
谁能给我一个解决这个问题的想法?我已经尝试过所有的表.它适用于 SQL 接口,但不适用于 Python.
Can anyone give me an idea to solve this? I have tried with all the tables. It works well on the SQL interface but not in python.
推荐答案
将 pat = r'C:\Users\pouru\Downloads\soccer' 更改为
change the pat = r'C:\Users\pouru\Downloads\soccer' to
pat = 'C:\Users\pouru\Downloads\soccer\'
这篇关于数据库错误:sql 上的执行失败:没有这样的表:联赛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!