Skip to content
Advertisement

Tag: flask-sqlalchemy

Flask-SQLAlchemy db.create_all() raises RuntimeError working outside of application context

I recently updated Flask-SQLAlchemy, and now db.create_all is raising RuntimeError: working outside of application context. How do I call create_all? This raises the following error: Answer As of Flask-SQLAlchemy 3.0, all access to db.engine (and db.session) requires an active Flask application context. db.create_all uses db.engine, so it requires an app context. When Flask handles requests or runs CLI commands, a

Flask admin – complex sort on hybrid_property

I have a fairly complex hybrid_property. This is a vendor model, which has multiple skuchannels (products). What it does is: Based on the target_stock_duration (e.g. we want to keep items in stock for 4 months) calculate how many units have to be ordered and how much this would cost. This gives us the potential. well this hybrid_property works just fine,

How to fix IntegrityError: (psycopg2.errors.ForeignKeyViolation) update or delete on table “users” violates foreign key constraint

I have two tables created with Flask-SQLAlchemy below – they have a one to one relationship. I would like to update the user table in a case when the user would like to have a new username: The db.session.commit throws the following error: The error says the logo table still has the old username but I have updated it and

Flask-sqlalchemy: When to close sessions?

I have created a python webapp with Flask and it seems like I am having connection issues with the database. I think this is because I don’t close my sessions somewhere in my code. I have for the database and use for adding records to the database. When do I have to close my session in this case? Is there

How to call a variable outside a validate() function which is inside the FlaskForm class

I have two def validate(self) functions within the RegistrationForm(FlaskForm). First function validates the user input if the car range is over 400km. The other function validates if the user lives far or close to work by calculating the distance between the user’s address and work address by means of geopy module. I’ve been told that def validate_field(self, field): function takes

How to filter after two joins in flask SQL alchemy

I have the following 3 tables: Each sample has a chain of processes it goes through and I need to get a table which includes both Sample.id and the latest date it has encountered a process, so that I can filter by this date. Something like this What I tried so far was looking at this and similar solutions: https://blog.miguelgrinberg.com/post/nested-queries-with-sqlalchemy-orm

No data available in table | Flask/Python/Sqlite

I am trying to use a simple app to display database information using Python, Flask and SQLite. I have three files server_table.html, server_table.py and base.html. My SQLite database testdb.db is constructed successfully and I am able to pull/push data to it. The columns and data type are correct for the database model. However, when I run server_table.py, the webpage renders

Advertisement