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 trialKristen Bouzaid
Data Analysis Techdegree Student 7,748 PointsSQLAlchemy Query to return a filtered list.."AssertionError: Regex didn't match"
OK. I'm stuck on this code challenge. The assignment is to return a list in the variable romance_movies that includes all movies in the db with the genre 'Romance'. I'm getting an "Assertion Error: Regex didn't match" on this code. The code from Line 17 and earlier was fine through the last code challenge. My only addition here is Line 20. I've tried including romance_movies = []
before Line 20. I've also tried using models.Movie
rather than just Movie
and using ==
instead of just =
...not sure where to go from here so any help would be much appreciated! Thank you!
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)
# Write your code below
romance_movies=session.query(Movie).filter_by(Movie.genre='Romance').all()
2 Answers
Asher Orr
Python Development Techdegree Graduate 9,408 PointsHi Kristen! This is the problem:
filter_by(Movie.genre='Romance').all()
Try removing the Movie. in front of genre. Like this:
romance_movies = session.query(Movie).filter_by(genre='Romance').all()
I believe Python already knows you're querying the model Class "Movie." You shouldn't have to specify it again in front of the column you're filtering by.
I hope this helps!
Kristen Bouzaid
Data Analysis Techdegree Student 7,748 PointsAh. OK. Will do. Never done this before so I'm learning as I go.
Kristen Bouzaid
Data Analysis Techdegree Student 7,748 PointsKristen Bouzaid
Data Analysis Techdegree Student 7,748 PointsThank you! I really appreciate the help!!
Asher Orr
Python Development Techdegree Graduate 9,408 PointsAsher Orr
Python Development Techdegree Graduate 9,408 PointsYou're welcome! Don't forget to mark "best answer," so others know you've been helped.