I really need to know why in the world we cannot change the column types after we do the migrations to Postgres
DB.
I already created my models by python manage.py makemigrations
then do migrate
. Everything looks fine and tables are created on the postgres DB.
class test_API(models.Model):
IDnumber = models.IntegerField(null=False, blank=False)
State = models.CharField(max_length = 256, null = True)
Exlcludmethod = models.CharField(max_length=256, null=True)
class test_API_2(models.Model):
Idnumber = models.Foreignkey(test_API, max_length = 256, blank=False, null = False)
value = models.CharField(max_length=128, default="")
last_updated = models.DateTimeField(auto_now=True)
Lets say we want to make change to IDnumber column from Integerfield
to Charfield
.
class test_API(models.Model):
IDnumber = models.CharField(null=False, blank=False)
State = models.CharField(max_length = 256, null = True)
Exlcludmethod = models.CharField(max_length=256, null=True)
and run the python manage.py makemigrations
again
return self.cursor.execute(sql) psycopg2.errors.DuplicateTable: relation "test_API" already exists
How can we modify/change column types and do migrations. What is the proper way of doing this ?
Using Django:Django==4.0.3 Python = 3.9.1 Posgresql = 2.9.3