“没有这样的桌子:运动”从SQLite DB导出表(Django View)
在我的django视图中,更新了表格后,我将此代码放入CSV文件中:
import sqlite3 as sql
import os
import csv
# export Data
print ("Export data into csv file..............")
conn = sql.connect('sqlite3.db') # I tried: db.sqlite3 -> same
cursor=conn.cursor()
cursor.execute("select * from Sport")
with open("heartrateai_data.csv", "w") as csv_file:
csv_writer = csv.writer(csv_file, delimiter="\t")
csv_writer.writerow([i[0] for i in cursor.description])
csv_writer.writerows(cursor)
dirpath = os.getcwdb()+"/heartrateai_data.csv"
print("Data exported Successfully into {}".format(dirpath))
conn.close()
但是它给了我错误:例外值:没有这样的表:Sport 。 我确定表名是正确的,因为我的model.py中是相同的。
我不确定是否可以使用连接和连接关闭来纠正线路。我是新手。 我的浏览器:
编辑2: 我看到编写路径的正确方法是“ e:\ ...'或r'e:...'。我在我的代码conn = sql.connect(r'e:\ work \ django \ Analysis \ Analysisdata \ db.sqlite3')
中写下了这样的书。 “没有这样的桌子:运动”
In my django view, after updating a table, I put this code for exporting that table into csv file:
import sqlite3 as sql
import os
import csv
# export Data
print ("Export data into csv file..............")
conn = sql.connect('sqlite3.db') # I tried: db.sqlite3 -> same
cursor=conn.cursor()
cursor.execute("select * from Sport")
with open("heartrateai_data.csv", "w") as csv_file:
csv_writer = csv.writer(csv_file, delimiter="\t")
csv_writer.writerow([i[0] for i in cursor.description])
csv_writer.writerows(cursor)
dirpath = os.getcwdb()+"/heartrateai_data.csv"
print("Data exported Successfully into {}".format(dirpath))
conn.close()
But it gives me the error: Exception Value: no such table: Sport.
I am sure that the table name is correct because is the same in my model.py.
I am not sure if it correct the line with connection and connection close. I am new in this.
My browser:
Edit 2:
I saw that the correct way to write the path is with 'E:\...' or with r'E:...'. I wrote like this in my code conn = sql.connect(r'E:\Work\django\analysisData\db.sqlite3')
but I have the same error. "No such table: Sport"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下
这可能只是Django的错误
Try this
it can be just Django's error
在我的代码中编写了这一行之后:
我看到表的名称与Model.py中的名称不同。表的名称为:projectName_nameoftable。
我修改了表名称,但我没有这个错误。
After I wrote this lines in my code:
I saw that the name of the table isn't the same like in the model.py. The name of tables is: projectName_NameOfTable.
I modified the table name, and I don't have that error again.