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 trialJonathan Grieve
Treehouse Moderator 91,253 PointsAdd a new movie instance to the database
Now, what could I be doing wrong here? It looks to me like I've correctly added a movie instance. It's asking me to create a variable called new_movie
which I've done. And assign a new instance.
But I only get the following.
Bummer: You should have a variable called new_movie that creates an instance of Movie().
The only thing I can think of is an issue with indentation.
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)
Base = declarative_base()
class Movie(Base):
__tablename__ = βmoviesβ
id = Column(Integer, primary_key=True)
movie_title = Column(String)
genre = Column(String)
Session = sessionmaker(bind=engine)
session = Session()
new_movie = Movie(movie_title="Robin Hood: Prince of Thieves", genre="Action")
session.add(new_movie)
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, Jonathan Grieve! Your final two lines are defined inside the class. They should be moved over to the left so that they line up with the class
keyword. You want to make a new instance of Movie
from outside the class.
Hope this helps!
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 PointsThe actual issue is that the feeble regex used to evaluate the code does not like the colon : in the title. π€¦
if Jonathan Grieve, left his session statements inside the class, and even commented them out, the regex would still "pass" the code.
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherChris Freeman good call! I've alerted the education team
Jonathan Grieve
Treehouse Moderator 91,253 PointsJonathan Grieve
Treehouse Moderator 91,253 PointsHi there, yes I thought it might be something like this, but I had tried leaving those last 2 lines to line up in the global scope. Maybe affected by the issue Chris Freeman mentioned. π
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 PointsThis "passes" because only regex used to evaluate. It should fail due to
session
not defined outside the class. Code in comments will still "pass". Note: colon had to be removed to pass regex.The least they could do is run the code through a true parser to see if it compiles.
Jonathan Grieve
Treehouse Moderator 91,253 PointsJonathan Grieve
Treehouse Moderator 91,253 PointsSo all it took was a colonosc...... never mind. ;)
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 Pointsto be overly precise, and total ...ectomy, because a ; semi would still fail.