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


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