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 Creating a Movie Model

Javi Caballero
Javi Caballero
7,422 Points

Finally, your table needs some columns. Add Column, Integer, and String to your sqlalchemy imports. Create an id column

I'm a little confused about what they are telling me to do...

models.py
# insert your code here
from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base

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

class Movie(Base):
    __tablename__ = 'movies'

1 Answer

Asher Orr
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Asher Orr
Python Development Techdegree Graduate 9,409 Points

Hi Javi! In this challenge, you're creating a database (movies.db) with a table called "Movie."

This task is asking you to include specific columns in your table.

You need:

  • an id column that holds numbers and is a primary key.
  • a column called movie_title that holds strings.
  • a column called genre that holds strings

Let me show you my code from another project, and what it is doing:

class Product(Base):
    __tablename__ = "products"
    product_id = Column(Integer, primary_key=True)
# creates a product_id column. It holds an integer, and it will act as a primary key ID for each item added to the database.
    product_name = Column("Product Name", String)
# creates a product_name column. All data in this column must be strings.)
# Note: you don't HAVE to include "Product Name" in the parentheses after Column. 
# All "Product Name" does is format the title of the column when you open the database in a program like DB Browser for SQLite.
    product_price = Column("Product Price", Integer)
# creates a product_price column. All data in this column must be integers.
    product_quantity = Column("Product Quantity", Integer)
# creates a product_quantity column. All data in this column must be integers.
    date_updated = Column("Date Updated", DateTime)
#creates a date_updated column. All data in this column must be DateTime objects.

I hope this is helpful! Let me know if you have more questions!