When setting up my database structure, I was stupid enough to set a field called "student_id" as "primary_key=True" for my Student class. I only realised much later that there are (rare) occasions where it is necessary to change said "student_id". When doing that via a form, Django will automatically duplicate the student, which is not what I want.
I would like to change "primary_key=True" to "unique=True", and am wondering how to do that.
My current plan is to add a field called "id" to the Student class, apply the migrations, and to go into the shell and simply assign it a running number with a for loop:
counter = 0
for s in Student.objects.all():
counter += 1
s.id = counter
s.save()
I would then go back into my models.py and change the line "primary_key=True" to "unique=True". How do I make sure that Django then treats the "id" field as it would with classes without a primary key (ie automatically assign a new ID when a new student is added to the database)?