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 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()
Steven Parker
Steven Parker
231,236 Points

Can you provide a link to the challenge page?

2 Answers

Steven Parker
Steven Parker
231,236 Points

The 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.