SQLite PythonBlaze尝试在删除同名表后创建表,返回旧模式

2024-06-08 23:00:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图弄清楚,当我尝试使用一组不同的列名创建表时,为什么删除表的架构会返回?在

删除表之后,我可以在SQLite浏览器中确认该表已消失。一旦尝试通过ODO加载新文件,它就会返回一个错误“传入数据的列名与SQL表中现有SQL表名的列名不匹配”。然后我可以看到在数据库中使用先前删除的模式重新创建了同一个表!我试着在丢掉桌子后做一个真空声明,但还是一样的问题。在

我可以使用不同的表名来创建表,但是对于为什么不能使用之前删除的要使用的表名感到困惑?在

import sqlite3
import pandas as pd
from odo import odo, discover, resource, dshape

conn = sqlite3.connect(dbfile)
c = conn.cursor()

c.execute("DROP TABLE <table1>")
c.execute("VACUUM")

importfile = pd.read_csv(csvfile)

odo(importfile,'sqlite:///<db_path>::<table1'>)

ValueError: Column names of incoming data don't match column names of existing SQL table Names in SQL table:

Tags: ofimportexecutesqlitesqlnames架构table
1条回答
网友
1楼 · 发布于 2024-06-08 23:00:26
import sqlite3
import pandas as pd
from odo import odo, discover, resource, dshape

conn = sqlite3.connect('test.db')
cursor = conn.cursor();
table = """ CREATE TABLE IF NOT EXISTS TABLE1 (
                                        id integer PRIMARY KEY,
                                        name text NOT NULL
                                    ); """;
cursor.execute(table);

conn.commit(); # Save table into database.

cursor.execute(''' DROP TABLE TABLE1 ''');
conn.commit(); # Save that table has been dropped.

cursor.execute(table);
conn.commit(); # Save that table has been created.
conn.close();

相关问题 更多 >