How to define Integer array in Flask Migration to create new Table

1.5k views Asked by At

I want to create Table using Flask Migration tool for my Postgresql Database.

I have written my flask model as follow:

from flask.ext.security import Security, SQLAlchemyUserDatastore, UserMixin, RoleMixin, utils
class AdminUser(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    allow_center_list = db.Column(db.ARRAY(db.Integer))
    admin_profile_id = db.Column(db.Integer, db.ForeignKey('admin_profile.id'))
    created = db.Column(db.DateTime(), default=datetime.now)
    modified = db.Column(db.DateTime(), default=datetime.now)

    user = db.relationship("User", back_populates="admin_user")
    admin_profile = db.relationship("AdminProfile", back_populates="admin_user")

I want to user integer array for allow_center_list column.

When I try execute "flask db upgrade" command (after executing init and migrate command), I am getting error as follow:

sa.Column('allow_center_list', sa.ARRAY(Integer()), nullable=True),NameError: name 'Integer' is not defined

Please guide me how we can define Integer array in Flask SQLAlchemy model.

1

There are 1 answers

1
ACV On

This might be similar to this bug.

Try sa.Integer() instead.