Open HikariPL opened 1 year ago
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()
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?