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 SQLAlchemy Basics Introduction to SQLAlchemy Querying the Movie Database

Jorge Grajeda
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jorge Grajeda
Python Development Techdegree Graduate 8,186 Points

Is there something specific I am missing from my code to complete the challenge ?

I am feeling a bit lost on this challenge, I would really appreciate it if somebody could help me out. Thank you in advance !

models.py
from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

engine = create_engine('sqlite:///movies.db', echo=False)
Session = sessionmaker(bind=engine)
session = Session()
Base = declarative_base()

class Movie(Base):
    __tablename__ = 'movies'

    id = Column(Integer, primary_key=True)
    movie_title = Column(String)
    genre = Column(String)

romance_movies = session.query(Movies).filter_by(genre = romance_movies)

1 Answer

Rohald van Merode
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Rohald van Merode
Treehouse Staff

Hey Jorge Grajeda 👋

There are two issues going on in the last line you wrote there. You're currently querying Movies but the class is singular: Movie. You'll also want to have a look at what you're passing to the filter_by() method. Currently you're passing it the romance_movies variable that you're declaring but instead you'll want to filter the movies that have the genre of "Romance".

After those two adjustments your code should look like this and pass the challenge as expected:

romance_movies = session.query(Movie).filter_by(genre='Romance')