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
Sean Manners
14,816 PointsDatabase Locked
So, I've been stuck on the Flask Track since every time I attempt to follow along (Started back at the Macros video), I end up with a 'Database Locked' error.
Fixing it initially only took deleting the database and re-running the code. Now however, the issue persists as soon as the database is recreated for the newly attempted version.
It will work for roughly 30 seconds, and then I'll get a Jinja update saying 'peewee.OperationalError: database is locked' . I've tried a few different things, but I can't quite figure out what's causing it overall. Any insight, would be greatly appreciated.
I've taken a snapshot of the workspace here, if that helps. https://w.trhou.se/v6szgtduv7
Thank you!
Edit: I've also perused the community related to previous issues of similar nature, but I can't quite seem to find the resolution, day three of this particular issue.
2 Answers
Chris Freeman
Treehouse Moderator 68,468 PointsBased on this Community post, the process of creating the database can be interrupted by the OS which may cause the database lock to get corrupted. It's better to wrap the code using a DATABASE.transastion():
if __name__ == '__main__':
models.initialize()
try:
with models.DATABASE.transaction(): # added this wrapper
models.User.create_user(
username='kennethlove',
email='kenneth@teamtreehouse.com',
password='password',
admin=True
)
except ValueError:
pass
app.run(debug=DEBUG, host=HOST, port=PORT)
Alexander Davison
65,469 PointsTry typing rm social.db into the Console (make sure you are not in the Python shell or in the middle of running the Flask app). It should delete the file
Sometimes deleting files in the File Tree doesn't work.
~Alex
Sean Manners
14,816 PointsThanks Alex - I did give that a go, and it appeared to work for roughly the same duration - about 30 seconds. The error seems to be occurring when I try to use any sort of functionality on the preview (Registering, sign in, etc.), as whenever I submit/post, it returns with the database being locked.
Alexander Davison
65,469 PointsOuch... Tagging Kenneth Love & Chris Freeman
Sean Manners
14,816 PointsSean Manners
14,816 PointsThanks Chris, this did it. I suppose I overlooked that post, my apologies!