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 trialdeepak kumar pradhan
Courses Plus Student 3,133 Pointsi am not able to see the table after connecting to sqlite3 db. i ran these cmd sqlite3 students.db .tables
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.connect()
db.create_tables([Student],safe=True)
2 Answers
Josh Keenan
20,315 PointsHere's the problem, you don't close the database after, use:
db.close()
If I'm wrong post to this thread again!
Chris Freeman
Treehouse Moderator 68,441 PointsI ran your code locally (saved as dbtest.py) and inspected with sqline3
successfully:
$ python dbtest.py
$ sqlite3 students.db
SQLite version 3.8.2 2013-12-06 14:53:30
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
student
sqlite> .dump student
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE "student" ("id" INTEGER NOT NULL PRIMARY KEY, "username" VARCHAR(255) NOT NULL, "points" INTEGER NOT NULL);
CREATE UNIQUE INDEX "student_username" ON "student" ("username");
COMMIT;
sqlite> .q
$
What errors were you seeing?
James N
17,864 PointsJames N
17,864 Pointsyou are wrong... I try to type .tables into sqlite and it doesnt work!
with the myoutput.txt file above, i just basically mimicked exactly what the teacher did.
Josh Keenan
20,315 PointsJosh Keenan
20,315 PointsWhat? I don't understand what you mean?
I'll watch the video
James N
17,864 PointsJames N
17,864 Pointswhat don't you understand? to be more specific, when i type .tables, i don't get back anything.
James N
17,864 PointsJames N
17,864 Pointsdid i close it in the wrong spot?
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsJames. It might be helpful to start a new post. And post your models. How are you initing the DB? You posted
mycode.py
but ranpython students.py
Did you run
python mycode.py
?