I have a program that migrates data from a Microsoft Access database to a local sqlite database. It runs on a 32-bit Miniconda installation rather than the usual 64-bit version I use because the Access version is 32-bit. I reinstalled that 32-bit miniconda installation this morning after something happened with my IT department that moved some of anaconda's program files. The clean install seems to be working fine, but I'm getting a bizarre error message when I try to backup the sqlite database.
Calling sqlite3.Connection.backup raises the following error: 'sqlite3.Connection' object has no attribute 'backup'.
Except, of course, a sqlite3.Connection object does have an attribute called backup.
And, to make things even stranger, the file is being backed up. I can see a new file being created, but it's still throwing this error.
Here's a simplified version of the code that's causing the error:
I have a module called db that contains classes for connecting to both databases I have:
class SQL:
def __init__(self, alt_path=None):
if not alt_path:
pdir = Path("C:\\path\to\default\project\directory")
dbdir = pdir / "Data" / "db" / "SQL"
sql_path = dbdir / "jjp.db"
self.conn = sqlite3.connect(sql_path.as_posix())
else:
self.conn = sqlite3.connect(alt_path.as_posix())
self.cursor = self.conn.cursor()
self.table_names = [
table[0]
for table in self.cursor.execute(
"SELECT name FROM sqlite_master WHERE type = 'table'"
)
]
def backup(self, backup_con):
self.conn.backup(backup_con, pages=0)
backup_con.close()
def close(self):
self.conn.close()
I'm importing those classes in a module called backup:
from jjp import db
def create_backup_con(db_type):
today = datetime.today().strftime("%Y%m%d%H%M%S")
if db_type == "sql":
db_file = sql_backup_dir / f"jjp_backup_{today}.db"
conn = sqlite3.connect(db_file.as_posix())
return conn
elif db_type == "access":
db_file = acc_backup_dir / f"jjp_backup_{today}.accdb"
return db_file
def backup_sql():
sql = db.SQL()
bck = create_backup_con("sql")
sql.backup(backup_con=bck)
bck.close()
sql.close()
Here's the full error message output:
backup.backup_sql()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
in
----> 1 backup.backup_sql()
c:\users\path\to\backup.py in backup_sql()
38 sql = db.SQL()
39 bck = create_backup_con("sql")
---> 40 sql.backup(backup_con=bck)
41 bck.close()
42 sql.close()
c:\users\path\to\db.py in backup(self, backup_con)
159 """
160
--> 161 self.conn.backup(backup_con, pages=0)
162 backup_con.close()
163
AttributeError: 'sqlite3.Connection' object has no attribute 'backup'
Running python 3.6.10 32-bit miniconda distribution on a 64-bit machine running Windows 10.