How to fix django's db_type deprecation warning?

472 views Asked by At

After upgrading to a more recent Django version, I started getting this deprecation warning:

Django version 1.3, using settings 'demos.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
/Users/.....myfile.py:328: DeprecationWarning: inner has been called without providing a connection argument. 
  if 'integer' in x.db_type()

I realized it's caused by the Field.db_type method, which returns the database column data type for a Field. This method has been modified so to comply with the multi-database feature of recent versions of Django, so now it also requires a connection object as argument [check the django docs]

But how to pass that connection object? I don't get it..

1

There are 1 answers

0
magicrebirth On

... I found a solution that works. It's enough to import the connection from django.db, and pass that as an argument:

from django.db import connection 
if 'integer' in x.db_type(connection=connection):
    # do something...

Still wonder whether it's the right way of doing it though....