0

I'm new to sqlalchemy and flask. I inherited a project in which I need to add new columns to a table (new fields to a model). Here is what the model looks like.

class Area(db.Model):
    __tablename__ = 'areas'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.Text)
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    last_updated = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    author_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    site_id = db.Column(db.Integer, db.ForeignKey('sites.id'))
    ttz = db.relationship("TTZInput", uselist=False)
    contaminants = db.relationship('ContaminantInput', backref='area', lazy='dynamic')
    outputs = db.relationship('AreaOutput', uselist=False, cascade="all, delete-orphan")
    app_input = db.relationship('ApplicationInput', uselist=False)
    order_status = db.Column(db.Boolean, default=False)
    public_handle = db.Column(db.VARCHAR, unique=True, index=True)
    area_note = db.Column(db.Text, default='')
    area_type = db.Column(db.Text, nullable=True)

area_type, the last field/column, is the newly added field/column. I've tried flask db migrate, but I keep getting "No changes in schema detected." What could be wrong?

mikejay93
  • 11
  • 2
  • Does the `area_type` field exist in your database, or only in the model? – Miguel Grinberg Sep 26 '20 at 18:18
  • Hey! alembic creates Python code to setup the database and its migration. Take a look at the files and see if they already contain instructions to create 'area_type'. In my project the files are stored in the `migrations/versions` directory. – oschlueter Sep 27 '20 at 17:06

0 Answers0