close

How do I know if I can disable SQLALCHEMY_TRACK_MODIFICATIONS?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How do I know if I can disable SQLALCHEMY_TRACK_MODIFICATIONS in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How do I know if I can disable SQLALCHEMY_TRACK_MODIFICATIONS?

  1. How do I know if I can disable SQLALCHEMY_TRACK_MODIFICATIONS?

    Since I had some copy'n'paste fights before getting this right I'd like to make it easier for the next one that will be in my shoes.

  2. know if I can disable SQLALCHEMY_TRACK_MODIFICATIONS

    Since I had some copy'n'paste fights before getting this right I'd like to make it easier for the next one that will be in my shoes.

Method 1

Jeff Widman’s detailed explanation is simply perfect.

Since I had some copy’n’paste fights before getting this right I’d like to make it easier for the next one that will be in my shoes.

In your code, immediately after:

app = Flask(__name__)

If you want to enable track modifications simply add:

app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True

Otherwise, if you are not using this feature, you may want to change the value to False in order not to waste system resources. This will still silence the warning since you’re anyway explicitly setting the config.

Here’s the same snippet with False value:

app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

Thanks to Jeff Widman for this added suggestion and details.

Method 2

If you have questions like this, then you definitely don’t need this feature.

By the way, the top answer is outdated. From version 2.1 (released on Oct 23, 2015), this config SQLALCHEMY_TRACK_MODIFICATIONS defaults to None. That’s mean the tracking behavior defaults to disabled, you don’t need to worry about memory loss.

Unless you are bothered with the terminal warning, you can suppress the warning by setting it to False:

from flask import Flask

app = Flask(__name__)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db = SQLAlchemy(app)

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read