D
D
domanskiy2020-09-04 09:58:14
Flask
domanskiy, 2020-09-04 09:58:14

How to set arguments for data types fields in models.py?

There is Flask+SQLAlchemy+MtSQL
How to set arguments for MySQL Data Types in models.py?
It is necessary to set (8,4) for Float
Or set the parameter for SMALLINT (3)

Tried:

vgap = db.Column(db.FLOAT(precision=10, scale=2), nullable=False)


An exception is thrown:
TypeError: __init__() got an unexpected keyword argument 'scale'

The model itself:
class DieCut(db.Model):
    __tablename__ = 'diecut'
    cut_name = db.Column(db.String(length=40), primary_key=True, nullable=False)
    zub_num = db.Column(db.SMALLINT, db.ForeignKey('zub.zub_num'))
    vsheet = db.Column(db.Integer, nullable=False)
    hcountitem = db.Column(db.Integer, nullable=False)
    vcountitem = db.Column(db.Integer, nullable=False)
    hgap = db.Column(db.FLOAT, nullable=False)
    vgap = db.Column(db.Float(precision=10, scale=2), nullable=False)
    cut_id = db.Column(db.Integer, autoincrement=True)
    slug = db.Column(db.String(50))
    cut_file = db.Column(db.String(200))

    def __init__(self, *args, **kwargs):
        super(DieCut, self).__init__(*args, **kwargs)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-09-04
@domanskiy

https://docs.sqlalchemy.org/en/13/core/type_basics...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question