如何修复 django 的 db_type 弃用警告?
升级到更新的 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 方法引起的,该方法返回 Field 的数据库列数据类型。此方法已被修改,以便符合 Django 最新版本的多数据库功能,因此现在它还需要一个连接对象作为参数 [检查 django 文档]
但是如何传递该连接对象?我不明白..
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..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
...我找到了一个有效的解决方案。从 django.db 导入连接并将其作为参数传递就足够了:
仍然想知道这是否是正确的方法......
... I found a solution that works. It's enough to import the connection from django.db, and pass that as an argument:
Still wonder whether it's the right way of doing it though....