I’m making a Flask-SqlAlchemy app. In one model I want to store geo code data as a lat/long.
From reading other posts, I should use Numeric not Float.
The documentation for type Numeric lists several arguments available:
precision=None, asdecimal=False, decimal_return_scale=None
So I tried adding a column as
db.Column(db.Numeric, precision=8, asdecimal=False, decimal_return_scale=None) — as the equivalent of DECIMAL(10,8)
Which returned an error of:
"Unknown arguments passed to Column: " + repr(list(kwargs)))
sqlalchemy.exc.ArgumentError: Unknown arguments passed to Column: ['asdecimal', 'decimal_return_scale', 'precision']
If I use db.Column(db.Numeric), I’m able to create the tables and write to it.
Would someone explain to me if there is a syntax error in what I passed here: db.Column(db.Numeric, precision=8, asdecimal=False, decimal_return_scale=None) — as the equivalent of DECIMAL(10,8)
What is the proper way to utilize/define a Numeric type column.
Flask-SQLAlchemy is a Flask extension that makes using SQLAlchemy with Flask easier, providing you tools and methods to interact with your database in your Flask applications through SQLAlchemy. In this tutorial, you'll build a small student management system that demonstrates how to use the Flask-SQLAlchemy extension.
One of which is that Flask-SQLAlchemy has its own API. This adds complexity by having its different methods for ORM queries and models separate from the SQLAlchemy API. Another disadvantage is that Flask-SQLAlchemy makes using the database outside of a Flask context difficult.
PickleType. Holds Python objects, which are serialized using pickle.
From SQLAlchemy docs: nullable – If set to the default of True, indicates the column will be rendered as allowing NULL, else it's rendered as NOT NULL. This parameter is only used when issuing CREATE TABLE statements.
You can also do
db.Column(db.Numeric(10,2))
Where the first element is the quantity of integer places and the second argument represents the amount of decimal places.
You should add the extra arguments to db.Numeric, and not to db.Column:
db.Column(db.Numeric(precision=8, asdecimal=False, decimal_return_scale=None))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With