[Answered ]-Django primary key does not exist

1👍

try adding id=i in c = City(). So that every time you create a new one, the id is adding 1 to it.

c = City(id=i, name=line[1], uniqueID=i,
         xcoord=int(line[3]), ycoord=int(line[2]),
         country=line[4],
         population=line[5], times_played=line[6], average_distance=line[7],
         difficulty_rating=line[8])  

1👍

id in Your model has type AutoField. This type of firld automaticaly increment values when new row is added.

You can overwrite id when You create a new row

c = City(id=1, name='test', ...)
c.save()
City.objects.get(pk=1)

or read inserted id after save model

c = City(name='test', ...)
c.save()
lastId = c.pk
City.objects.get(pk=lastId)

Leave a comment