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 trialMark Jeffreys
9,072 PointsWhy is workspace throwing a peewee.OperationalError: no such column: t1.user_id
I'm working on building the TacoCat web application, and i can't figure out why PeeWee is throwing this error when trying to open index.html: peewee.OperationalError: no such column: t1.user_id
I can't find any reference to the t1.user_id that it could are referencing. The only thing I can conceive of is that is the field in Taco used to reference the id of the user object that created the taco.
I haven't created any tacos yet, and I have the code to pull up the taco count (tacos = models.Taco.select().limit(100)), which I included in the index route, since the route was throwing errors when I tried to call index without the tacos argument. Based on the unit test, I know this is supposed to return the template with the text "No tacos yet", but I'm getting this error instead. Any help would be appreciated.
I didn't attach my code to this post since I've only done my work in the Workspace so far. Please let me know if you can help, or if you'd need to see my code before offering suggestions. Thank you.
-Mark
2 Answers
Mark Jeffreys
9,072 PointsI found out what the problem was. I forgot to include the class Meta: database = DATABASE line for the Taco class.
Chris Freeman
Treehouse Moderator 68,441 PointsHave you initialized your database tables for User and your other models?
# models.py
def initialize():
DATABASE.connect()
DATABASE.create_tables([User], safe=True)
DATABASE.close()
# app.py
import models
if __name__ == '__main__':
models.initialize()
Mark Jeffreys
9,072 PointsThank you for the suggestion, and yes I did, though I named by database variable db. Here's the redacted version of the code I used for that method:
#models.py
def initialize():
db.connect()
db.create_tables([User, Taco], safe=True)
db.close()
#tacocat.py
import models
DEBUG = True
PORT = 8000
HOST = '0.0.0.0'
if __name__ == '__main__':
models.initialize()
try:
models.User.create_user(
email='ae***nt@gmail.com',
password='password')
except ValueError:
pass
app.run(debug=DEBUG, host=HOST, port=PORT)
Chris Freeman
Treehouse Moderator 68,441 PointsIs it possible you are viewing a page that needs a user to be logged in. There may be some template code that needs to be wrapped in:
{% if current_user.is_authenticated %}
...
{% endif %}
If not, can you post your layout.html
base and index.html
templates?
Mark Jeffreys
9,072 PointsI'm trying to access index.html, and as far as I can tell, this doesn't require a user to be authenticated. Layout.html and index.html both have the default code that was included with the workspace for this challenge.
Here's layout.html:
<!doctype html>
<html>
<head>
<title>Tacocat</title>
<link rel="stylesheet" href="/static/css/normalize.css">
<link rel="stylesheet" href="/static/css/skeleton.css">
<link rel="stylesheet" href="/static/css/tacocat.css">
</head>
<body>
{% with messages=get_flashed_messages() %}
{% if messages %}
<div class="messages">
{% for message in messages %}
<div class="message">
{{ message }}
</div>
{% endfor %}
</div>
{% endif %}
{% endwith %}
<div class="container">
<div class="row">
<div class="u-full-width">
<nav class="menu">
<!-- menu goes here -->
</nav>
{% block content %}{% endblock %}
</div>
</div>
<footer>
<p>An MVP web app made with Flask on <a href="http://teamtreehouse.com">Treehouse</a>.</p>
</footer>
</div>
</body>
</html>
And here's index.html:
{% extends 'layout.html' %}
{% block content %}
<h2>Tacos</h2>
{% if tacos.count() %}
<table class="u-full-width">
<thead>
<tr>
<th>Protein</th>
<th>Cheese?</th>
<th>Shell</th>
<th>Extras</th>
</tr>
</thead>
<tbody>
{% for taco in tacos %}
<tr>
<!-- taco attributes here -->
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<!-- message for missing tacos -->
No tacos yet
{% endif %}
{% endblock %}
Mark Jeffreys
9,072 PointsI figured out what the problem was. I didn't include the class Meta for the Taco class, and I posted that as a new answer. Thank you for helping troubleshoot this!