如何获取刚刚保存的记录的ID [英] How to get the ID of the record just saved
本文介绍了如何获取刚刚保存的记录的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Django 1.3作为我的一个项目,我需要获取刚刚保存在数据库中的记录的ID。
I'm using Django 1.3 for one of my projects and I need to get the ID of a record just saved in the database.
我有一些像以下代码保存数据库中的记录:
I have something like the code below to save a record in the database:
n = MyData.objects.create(record_title=title, record_content=content)
n.save()
记录的ID刚刚保存自动递增。有没有办法获得该ID并在其他代码中使用它?
The ID of the record just saved auto-increments. Is there a way to get that ID and use it somewhere else in my code?
推荐答案
使用 n .id
保存后。
请参见自动递增主键。
这篇关于如何获取刚刚保存的记录的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文