0

I am trying to upload new data via the loaddata function in django. In order to not write over existing data, I need to add the new data with new incremental pk numbers. How do I find the last pk number in a specific table?

H C
  • 1,138
  • 4
  • 21
  • 39
  • Possible duplicate of [Django - Getting last object created, simultaneous filters](http://stackoverflow.com/questions/1256190/django-getting-last-object-created-simultaneous-filters) – solarissmoke Nov 07 '15 at 05:47
  • Why do you think you need to do this? pks are allocated automatically by the db. – Daniel Roseman Nov 07 '15 at 08:38

1 Answers1

0

According to: https://docs.djangoproject.com/en/1.8/ref/models/querysets/#latest

It would be:

obj = Foo.objects.latest('id')
Andrés Pérez-Albela H.
  • 4,003
  • 1
  • 18
  • 29