![](/img/trans.png)
[英]Get ID of new record in function trigger before insert on postgreSQL
[英]Django: model testing setUp get test record insert id
我是测试Django应用程序的新手,但我觉得应该有某种内部框架方法来检索上一个插入ID。
如何获取最后的插入ID?
苏丹
没有获取最后一个插入ID的特定方法,但是在插入时,您将获得包括该ID的整个对象。
new_instance = models.SomeModel(foo='something', bar='something else')
new_instance.save()
print new_instance.pk
new_instance = models.SomeModel.objects.create(foo='something', bar='something else')
print new_instance.pk
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.