close

[Solved] AttributeError: can’t set attribute when connecting to sqlite database with flask-sqlalchemy

Hello Guys, How are you all? Hope You all Are Fine. I was trying to connect my SQLite database with my flask application Yesterday code was working properly but suddenly I got AttributeError: can’t set attribute when connecting to SQLite database with flask-sqlalchemy this error. So Here I am Explain to you all the possible solution Here.

Without Wasting your time, Lets start This Article to Solve This Error in react-native.

How AttributeError: can’t set attribute when connecting to sqlite database with flask-sqlalchemy Error Occurs ?

Yesterday My Flask Project was working fine. When I run my project today suddenly I got error. When I examine my code, I cant see any issue. It also looks identical to the code of the working project, so I really don’t know what I am doing wrong.

Here is the errors:

(env) PS C:\my-projects\task-master-tdd> flask shell
Python 3.8.5 (tags/v3.8.5:580fbb0, March 20 2021, 10:04:08) [MSC v.1926 32 bit (Intel)] on win32
App: project [development]
Instance: C:\my-projects\task-master-tdd\instance
>>> from project import db
>>> db
Traceback (most recent call last):
AttributeError: can't set attribute
>>>

How to Solve AttributeError: can’t set attribute when connecting to sqlite database with flask-sqlalchemy ?

Question: How to Solve AttributeError: can’t set attribute when connecting to sqlite database with flask-sqlalchemy ?
Answer: SQLAlchemy is automatically installed as a dependency for Flask-SQLAlchemy and its latest release (1.4.0) introduces the following breaking change So You Have to just Downgrade your version. follow the below step to downgrade.

Solution 1: DownGrade sqlalchemy Version

just Downgrade your version. follow the below step to downgrade.

  1. Double-check that this issue affects you by running
  2. pip freeze
  3. You should find that the current version of sqlalchemy is 1.4.0
  4.  I found the quickest solution, for now, is to manually revert to a previous version of sqlalchemy:
  5. pip install SQLAlchemy==1.3.23
  6. Thats It.

Solution 2

  1. Just Freeze your packages
  2. pip freeze > requirements.txt
  3. Update your SQLAlchemy in your requirements.txt
  4. SQLAlchemy<1.4.0
  5. Reinstall the packages
  6. pip install -r requirements.txt

Solution 3

I Just Checked For This Error and I Found SQLAlchemy is automatically updated thats causing error.

SQLAlchemy is automatically installed as a dependency for Flask-SQLAlchemy and its latest release (1.4.0) introduces the following breaking change:

The URL object is now an immutable named tuple. To modify a URL object, use the URL.set() method to produce a new URL object.

I was able to fix this issue by simply installing the previous version of SQL Alchemy (1.3.23).

Relevant github issue tracking fixes: github.com/pallets/flask-sqlalchemy/issues/910

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries.

Also Read

Leave a Comment