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

getting a "peewee.OperationalError: no such column: t1.user_id" on the tacocat flask app?

I getting this t1 error on my project. I noticed that when I delete user I get another OperationError: no such column: t1.protein and I assume that same error would happen to the others.

tacocat.pt

@app.route('/')
def index():
    tacos = models.Taco.select().limit(100)
    return render_template('index.html', index=index, tacos=tacos)


@app.route('/new-taco', methods=('GET', 'POST'))
@login_required
def tacos():
    form = forms.TacoForm()
    if form.validate_on_submit():
        models.Taco.create(user=g.user._get_current_object(),
                            protein=form.protein.data.strip(),
                            shell=form.shell.data.strip(),
                            cheese=form.cheese.data.strip(),
                            extra=form.extra.data.strip())
        return redirect(url_for('index'))
    return render_template('taco.html', form=form)


@app.route('/tacos/<int:user_id>')
def veiw_tacos(user_id):
    tacos = models.Taco.select().where(models.Post.id == user_id)
    if tacos.count() == 0:
        flash("New site sorry We will have stuff on soon you could make the first post!")
    return render_template('index.html', tacos=tacos)

forms.py

class TacoForm(Form):
    protein = StringField("What type of protein is in your taco? Beans? Beef?", validators=[DataRequired()])
    shell = StringField("What type of shell is your taco?", validators=[DataRequired()])
    cheese = BooleanField("Cheese", default=True)
    extras = TextAreaField("Add any other detail.", validators=[DataRequired()])

models.py

class Taco(Model):
    user = ForeignKeyField(
        rel_model=User,
        related_name='tacos'
    )
    protein = CharField(max_length=25)
    shell = CharField(max_length=25)
    cheese = BooleanField()
    extras = TextField()

    class Meta:
        databse = DATABASE
        indexes = (
            (('user', 'protein', 'shell', 'cheese', 'extras'), True)
        )



def initialize():
    DATABASE.connect()
    DATABASE.create_tables([User, Taco], safe=True)
    DATABASE.close()
Chris Freeman
Chris Freeman
Treehouse Moderator 68,468 Points

Have you recreated your database since adding the user field to the Taco model?

Chris Freeman
Chris Freeman
Treehouse Moderator 68,468 Points

Is this still an issue? If so, I could look further into it if you can post a link to a snapshot of your Workspace.