I am running Python3 on my Mac testing simple sql database. I have the below code
import sqlite3
# connecting to the database
connection = sqlite3.connect("myTable.db")
crsr = connection.cursor()
# SQL command to create a table in the database
sql_command = """CREATE TABLE emp (
staff_number INTEGER PRIMARY KEY,
fname VARCHAR(20),
lname VARCHAR(30),
gender CHAR(1),
joining DATE);"""
# execute the statement
crsr.execute(sql_command)
# SQL command to insert the data in the table
sql_command = """INSERT INTO emp VALUES (23, "Rishabh", "Bansal", "M", "2014-03-28");"""
crsr.execute(sql_command)
crsr.execute(sql_command)
connection.commit()
connection.close()
When I run this code, I am getting error:
Traceback (most recent call last):
File "test.py", line 8, in <module>
connection = sqlite3.connect("myTable.db")
sqlite3.OperationalError: unable to open database file
What am I missing? I tried replacing ("myTable.db") with (".myTable.db") and ("./myTable.db") but same issue. Please suggest.
print(os.getcwd())to your script as a debugging aid.