Monday 31 October 2022

How to add property to PostgreSQL database that is hosted on Heroku with Flask/Python?

I have a database for my website that is hosted on Heroku and uses Flask and Python. The model structure looks like:

class MyDataModel(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    property1 = db.Column(db.String(240), default = "")
    property2 = db.Column(db.String(240), default = "")
    property3 = db.Column(db.String(240), default = "")

When I try to update this model to something with an additional property (property4) shown below, the website doesn't work. Is there a way to add an additional property to a model so that the model still functions properly?

class MyDataModel(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    property1 = db.Column(db.String(240), default = "")
    property2 = db.Column(db.String(240), default = "")
    property3 = db.Column(db.String(240), default = "")
    property4 = db.Column(db.String(240), default = "")

The db is set up like:

db = SQLAlchemy()
app = Flask(__name__)
db.init_app(app)


from How to add property to PostgreSQL database that is hosted on Heroku with Flask/Python?

No comments:

Post a Comment