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 trialLucas Andrews
4,919 PointsRunning command .tables indicates that initialize() does not appear to be creating Entry as a table.
Here is the class and initialise() code:
class Entry(Model):
content = TextField()
timestamp = DateTimeField(default=datetime.datetime.now)
class Meta:
databse = db
def initialize():
"""Create the database and the table if they don't exist."""
db.connect()
db.create_tables([Entry], safe=True)
And later in the document, here is where initialize() is called:
if __name__ == '__main__':
initialize()
menu_loop()
Any assistance would be much appreciated - thanks.
2 Answers
Kris Powell
6,246 PointsHi! I'm not sure if it's causing your issue, but I noticed a typo:
class Entry(Model):
content = TextField()
timestamp = DateTimeField(default=datetime.datetime.now)
class Meta:
databse = db
database variable should be:
class Meta:
database = db
gl! kris
Kris Powell
6,246 PointsYour OrderedDict is commented-out there, if you cut it from where it is, above the Entry class, and paste it below your delete_entry() method, but before dunder name, uncomment it, you should have some success. Let me know :)
Kris Powell
6,246 PointsSorry! I got carried away there. I can't see why your tables aren't being created. Part of your menu loop might be indented incorrectly, but it shouldn't have any effect on the initialize() method. I don't know if it will help but are you running the file on a local machine or in workspaces? Maybe there could be an issue with your sqlite3 install? Sorry if I confused things! kris
edit: Now that I see your code on a desktop screen rather than mobile, it is easy to see why you have commented those blocks.
Kris Powell
6,246 PointsI ran your code without any problem on my machine. Checked sqlite and the entry table was present. Wish I could be more help :/
Lucas Andrews
4,919 PointsThanks, Kris - I'm running this on Workspaces. Interesting that you were able to run it on your end. I'll try to run the script in Python 3.5.2 Shell for Windows (I've only been using Workspaces so far).
Lucas Andrews
4,919 PointsLucas Andrews
4,919 PointsThanks, Kris - I've corrected that typo, but calling .tables still doesn't return any results. Here's the code in full: