# Creates or opens a file called mydb with a SQLite3 DB db = sqlite3.connect('data/mydb') # Get a cursor object cursor = db.cursor() # Check if table users does not exist and create it cursor.execute('''CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, phone TEXT, email TEXT unique, password TEXT)''') # Commit the change db.commit() # Catch the exception except Exception as e: # Roll back any change if something goes wrong db.rollback() raise e finally: # Close the db connection db.close()