SQLite Python Blaze - Attempting to create a table after dropping a table of same name returns old schema

299 views Asked by At

I am trying to work out why the schema of a dropped table returns when I attempt to create a table using a different set of column names?

After dropping the table, I can confirm in an SQLite explorer that the table has disappeared. Once trying to load the new file via ODO it then returns an error "Column names of incoming data don't match column names of existing SQL table names in SQL table". Then I can see the same table is re-created in the database, using the previously dropped schema! I attempted a VACUUM statement after dropping the table but still same issue.

I can create the table fine using a different table name, however totally confused as to why I can't use the previously dropped table name I want to use?

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:
1

There are 1 answers

2
grimur82 On
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();