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
Tag: flask-sqlalchemy
How to collect WTForms data through loop without explicitly stating the name of each field?
I am following CoreyMSchafer’s Flask-blog tutorial. Here, I can create, update and delete posts using WTForms and SQLAlchemy. However, to do that, I have to explicitly mention the name of the form fields. For example, to update a post (assuming a post only has title and content): where the model is and the WTForm is However, what if my form
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,
ImportError: cannot import name ‘app’ from partially initialized module ‘market’ (most likely due to a circular import)
I was trying to package my code as it was getting kind of complex for me to keep in one file and i encountered an import error when i tried to run the file that says circular import error, how do i solve this error? I have been analyzing the code and i cannot seem to be able to figure
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
Flask_SQLAlchemy is claiming my value is not boolean?
I ran into the following error: I tried as boolean input everything ranging from 0|1, FALSE|TRUE, False|True on my main route. I have also tried to put in the boolean values inbetween quotations. What am I doing wrong? My base route being as follows Answer The problem you have is that the form submission is returning the selection value as
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