Home > Software design >  What are all the options when instantiating a Flask-SQLAlchemy Column?
What are all the options when instantiating a Flask-SQLAlchemy Column?

Time:06-08

I'm starting a Flask project and I'm using Flask-SQLAlchemy. When I instantiate a model, I get to pick certain parameters in db.Column like primary_key, index, unique:

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), index=True, unique=True)
    email = db.Column(db.String(120), index=True, unique=True)
    password_hash = db.Column(db.String(128))

I looked at the documentation but I couldn't find a clear list of every option and their respective functionality.

What parameters can I use in db.Column and what exactly do they do?

CodePudding user response:

These are listed here, under Column, Table, MetaData API.

For example, primary_key is documented as

primary_key – If True, marks this column as a primary key column. Multiple columns can have this flag set to specify composite primary keys. As an alternative, the primary key of a Table can be specified via an explicit PrimaryKeyConstraint object.

  • Related