-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid precision value error #2360
Comments
Dear All, any ideas how to fix it? |
No the issue cannot be resolved by use_setinputsizes=False. It is not working. I tried the following code. Not working at all import argparse
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_admin import Admin
from flask_admin.contrib.sqla import ModelView
from sqlalchemy import create_engine
app = Flask(__name__)
# Setup the Flask app
app.config['SECRET_KEY'] = 'mysecret'
app.config['SQLALCHEMY_DATABASE_URI'] = "YOUR SQL SERVER DB connection"
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
# Optionally, if you want to perform some operations directly with the engine, you can create it like this:
engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'], echo=True, use_setinputsizes=False)
class User(db.Model):
__tablename__ = 'user'
__table_args__ = {'schema': 'DevApp'}
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(150), unique=True)
email = db.Column(db.String(150))
admin = Admin(app, name='My App Admin', template_mode='bootstrap3')
admin.add_view(ModelView(User, db.session))
def create_db():
"""Creates the database tables."""
with app.app_context():
db.create_all()
print('Database tables created successfully.')
def drop_db():
"""Drops the database tables."""
with app.app_context():
db.drop_all()
print('Database tables dropped successfully.')
def run_app():
app.run(debug=True)
def main():
parser = argparse.ArgumentParser(description="Manage the Flask application.")
parser.add_argument('command', choices=['run', 'create_db', 'drop_db'],
help='the command to run')
args = parser.parse_args()
if args.command == 'run':
run_app()
elif args.command == 'create_db':
create_db()
elif args.command == 'drop_db':
drop_db()
if __name__ == '__main__':
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I have been using flask_admin for approx. 2 years in my flask app, but recently (after updating all packages) it stopped working. I can open front page of flask admin panel, but whenever I try to display content of a table then I get the following error:
I am connecting to SQL Server via pyodbc. I think it must be linked with this issue GitHub.
Possibly explicit input size is needed when admin creates engine:
e = create_engine("mssql+pyodbc://...", use_setinputsizes=False)
Any ideas how to easily solve it?
The text was updated successfully, but these errors were encountered: