如何在保留旧表内容的同时将django表中的所有行复制到新表中?
答案 0 :(得分:2)
from django.db import connection, transaction
cursor = connection.cursor()
# commit required
cursor.execute("SELECT * INTO %s FROM %s" % (newtable, oldtable))
transaction.commit_unless_managed()
使用模型对象,表名将存储在_meta.db_table