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.


In Flask i want to make 1:1 relationships, How can i do that with SQL-Alchemy.

I want to make a profile for user in one to one relationships tables. How can i do it for User, and User's profile.

Also i want to show join them together.. How can i join profile and users table for CRUD operations.

Thank you so much..

class User(UserMixin, db.Model):
    __tablename__ = 'users'
    id = db.Column('user_id', db.Integer, primary_key = True)
    email = db.Column(db.String(128), unique = True)
    password = db.Column(db.String(200))
    is_admin = db.Column(db.Boolean, default=False)
    is_active = db.Column(db.Boolean, default = False)
    token = db.Column(db.String(100), unique = True)
    profile = relationship("Profile", lazy = "joined")

    def __init__(self, email, password, token, is_admin = False, is_active = False):
        self.email = email
        self.password = self.GenerateHash(password)
        self.is_active = is_active
        self.is_admin = is_admin
        self.token = token