Let's suppose I have the following model:
class Test(models.Model):
field_one = models.CharField(max_length=80)
Now, we have created 2-3 Model objects with field_one field.
p1 = Test(field_one="Object1")
p1.save()
p2 = Test(field_one="Object2")
p2.save()
Later, I realised that I need to add another field field_two to my Test model.
class Test(models.Model):
field_one = models.CharField(max_length=80)
field_two = models.IntegerField(default=3)
- Now, Doing
makemigrations&migrateand running server.
which will prompt the following error
django.db.utils.ProgrammingError: column mainapp_test.field_two does not exist
- I understand that this error occurs due to my
2existing objects inPostGresDBdoesn't havefield_twocolumn.
Is there any effective way to add field_two column to my existing objects with some default value? or How to solve this problem?
Django Version: 2.0 Django ORM DB: PostGresql
makemigrations?