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

Some doubts when deploying Flask project to Heroku

I have the social network ready to deploy to Heroku but Heroku only supports Postgres Databases. I have found that Postgres works very well with SQLAlchemy so should I change all the models from Peewee to SQLAlchemy? What can I do in cases like this?:

    class User(UserMixin, Model):
        username = CharField(unique=True)
        email = CharField(unique=True)
        password = CharField(max_length=100)
        joined_at = DateTimeField(default=datetime.datetime.now)
        is_admin = BooleanField(default=False)

    def name_exists(form, field):
        if User.select().where(User.username == field.data).exists():
             raise ValidationError('User with that name already exists.')

All I came up with is this:

    class User(UserMixin, db.Model):
        id = db.Column(db.Integer, primary_key=True)
            username = db.Column(db.String(80), unique=True)
            email = db.Column(db.String(120), unique=True)

1 Answer

You don't need to change your models. You can still connect to a Postgres database through Peewee. You just need to create a Postgres database handle when the app runs on Heroku.