【问题标题】:from south.db import db replaced by what in django 1.7+?从 south.db 导入 db 替换为 django 1.7+ 中的什么?
【发布时间】:2015-01-19 20:44:59
【问题描述】:

我正在修改其他人的代码以使用 django 1.8 运行,我想知道是否可以直接替换该行

 from south.db import db

用途包括:

if db.backend_name == "postgres":
    db.start_transaction()
    db.execute_many(commands.PG_DISABLE_TRIGGERS)
    db.commit_transaction()

【问题讨论】:

    标签: django django-south django-1.7


    【解决方案1】:

    据我了解,替换为:

    from django.db import connection
    from django.db import transaction
    

    用法:

    >>> from django.db import connection
    >>> connection.vendor
    u'postgresql'
    

    还有:

    from django.db import connection
    from django.db import transaction
    
    cursor = connection.cursor() 
    with transaction.atomic():
        cursor.executemany(commands.PG_DISABLE_TRIGGERS)
    

    【讨论】:

      猜你喜欢
      • 2014-04-12
      • 1970-01-01
      • 2015-09-26
      • 1970-01-01
      • 2012-08-30
      • 1970-01-01
      • 2016-03-06
      • 1970-01-01
      • 2020-02-05
      相关资源
      最近更新 更多