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 trialGabriel Guerra
Data Analysis Techdegree Graduate 9,109 PointsSqlalchemy Movie challenge
HI there Any idea why I don't pass this challenge, I get the error message: 'You should have a variable called new_movie that creates an instance of Movie().'
Thanks!
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)
def __repr__(self):
return f'<User(movie_title={self.movie_title}, genre={self.genre})>'
if __name__ == "__main__":
Base.metadata.create_all(engine)
new_movie = Movie(movie_title = "Lord of the rings", genre = "Fantasy")
session.add(new_movie)
session.commit()
2 Answers
Steven Parker
231,236 PointsThe challenge seems to be a stickler for "best practice" syntax, and apparently doesn't like the spaces around the equal signs where named arguments are being passed.
Also, it looks like you did a few extra things like adding a "__repr__" method to the Movie, a call to a create_all method, and adding a test for "__main__". As a general rule to avoid confusing the challenge checker, do only what the instructions ask for.
Gabriel Guerra
Data Analysis Techdegree Graduate 9,109 PointsHI Steven For sure, it's coding Challenge number 2: https://teamtreehouse.com/library/sqlalchemy-basics/introduction-to-sqlalchemy/movie-database-continued Lg Gabriel
Steven Parker
231,236 PointsSteven Parker
231,236 PointsCan you provide a link to the challenge page?