【问题标题】:How to fix django's db_type deprecation warning?如何修复 django 的 db_type 弃用警告?
【发布时间】:2011-11-07 10:18:32
【问题描述】:

升级到更新的 Django 版本后,我开始收到此弃用警告:

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]

但是如何传递那个连接对象呢?没看懂。。

【问题讨论】:

    标签: django deprecated dbtype


    【解决方案1】:

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

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

    仍然想知道这是否是正确的做法......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多