How to provide SQL as NOLOCK when using the Django Model Queries

I have a Django Users model mapped to an existing MS SQL Server database table. I read the table like this:

Users.objects.filter(userid='xyz').filter(status='active') 

I want to know which lock constructors could translate, for example, into this type of reading Lock the table? In SQL, I would do:

 SELECT * from users (nolock) where userid='xyz' and status='active' 

Is there a way to explicitly specify "nolock" through Django Model queries?

I searched a lot in the Django documentation as well as the django-pyodbc documentation without any success.

Thanks.

ps: Using django-pyodbc and pyodbc drivers

+4
source share
1 answer

You can create a view:

 create view dbo.vw_Users as select col1 , col2 , ... from dbo.Users with (nolock) 

And read Django from the view instead of the table.

+1
source

Source: https://habr.com/ru/post/1393212/


All Articles