Rob
Rob

Reputation: 59

Python not creating sqlite3 database

Hello there i am just working with sqlite3 in python (3.9) and have the following basic command.

import sqlite3

conn = sqlite3.connect(r'C:\python\pythonCode\NewDB.db')
cursor = conn.cursor()
sql = '''create table students (
    id int,
    name text,
    username text)'''
cursor.execute(sql)
cursor.close()

i dont get any errors when i run i cannot see any db file in the C: location in the connect()

Can someone point me in the right direction please.

Upvotes: 2

Views: 1067

Answers (1)

c00kie
c00kie

Reputation: 306

This code seems fine to me - but by the behaviour you describe, it sounds as if your application is not getting sufficient rights to create the file: you are telling your code to create a file within your C:\python directory.

I would suggest running your Python script as administrator [run CMD as admin and then python3 file.py]. If you don't want to go down this route, then change the database directory to something like your desktop to avoid any privilege issues.

I hope this solves your error! Let me know.

Upvotes: 2

Related Questions