2011-11-07 209 views
0

升级到较新的Django版本后,我开始这个弃用警告:如何解决django的db_type deprecation警告?

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() 

我意识到它是由Field.db_type方法,该方法返回一个领域的数据库中列的数据类型引起的。该方法已被修改,以符合了最新版本的Django的多数据库功能,所以现在还需要一个连接对象作为参数 [check the django docs]

但如何通过该连接对象?我不明白它..

回答

0

...我找到了一个可行的解决方案。这足以导入从django.db连接,并传递作为参数:

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

仍然不知道它是否是虽然做的正确的方式....