Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Using Databases in Python Meet Peewee Modeling

nicole lumpkin
nicole lumpkin
Courses Plus Student 5,328 Points

Accessing sqlite3 students.db in Terminal

So far I've been learning the Python track through my IDE Spyder which is ran through Anaconda. I have little to no experience using terminal but I was able to access SQLite by typing the command sqlite3 student.db. Similar to the video my version of SQLite opened, and I input '.tables', however, student did not appear. Does anyone have any insight as to why??

1 Answer

Dear Nicole,

I think your database is just "empty" there is no table.

Did you execute before something like that?

from peewee import *

db = SqliteDatabase('students.db')

class Student(Model):
  username = CharField(max_length=255, unique=True)
  points = IntegerField(default=0)

  class Meta:
    database = db

if __name__ == '__main__':
  db.create_tables([Student], safe=True)

or might you can try something like that

import sqlite3

con = sqlite3.connect('Your_path_to_the_DB')

with con:
        cur = con.cursor()
        cur.execute("CREATE TABLE Students(Id INT, Name TEXT)")

But you need to create the table than you can look inside of the DB and see it.

I reproduced it on the workingspace and sqlite3 students.db .tables

worked for me. (after running code)

Greetings Julian

nicole lumpkin
nicole lumpkin
Courses Plus Student 5,328 Points

Because this is my first experience using anything database related I wasn't sure what was necessary. I did run your first chunk of code within Spyder. Are you saying I need to run that code within Terminal. Or perhaps do I need to navigate to the directory in which students.py is located and then run sqlite3 students.db from there?

nicole lumpkin
nicole lumpkin
Courses Plus Student 5,328 Points

Hooray!! I navigated to the directory that contained students.py and everything worked! Thanks Julian Steffen