Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Flask with SQLAlchemy Basics Connecting to a Database with SQLAlchemy SQLAlchemy and Flask

Asher Orr
seal-mask
.a{fill-rule:evenodd;}techdegree
Asher Orr
Python Development Techdegree Student 5,945 Points

What is the difference between string and text in Python?

Hi everyone! In the video, all but one database column are String datatypes.

The last one is a Text datatype:

class Pet(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    created = db.Column('Created', db.DateTime, default=datetime.datetime.now)
    name = db.Column('Name', db.String())
    age = db.Column('Age', db.String())
    breed = db.Column('Breed', db.String())
    color = db.Column('Color', db.String())
    size = db.Column('Size', db.String())
    weight = db.Column('Weight', db.String())
    url = db.Column('URL', db.String())
    url_tag = db.Column('Alt Tag', db.String())
    pet_type = db.Column('Pet Type', db.String())
    gender = db.Column('Gender', db.String())
    spay = db.Column('Spay', db.String())
    house_trained = db.Column('House Trained', db.String())
    description = db.Column('Description', db.Text())

What exactly is the difference between a string and text? Also, what is the advantage of making "description" text?

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 90,824 Points

They're basically the same, but text allows more characters for a field name. It's useful when data you use doesn't have a defined length for database purposes. You'll use db.String most of the time but for description fields like in this example, it's more prudent to use db.Text().