I am running the Django service in a docker container. Django has a Postgres database remote access from AWS RDS, and all this is working fine. But I am adding a new field (amount) in Model.
class MyModel(models.Model):
model_id = models.UUIDField(default=uuid.uuid4)
model2 = models.ForeignKey(MyModel2, on_delete=models.CASCADE, related_name='mymodels')
amount = models.FloatField(default=0) # this is new field
updated_at = models.DateTimeField(auto_now=True)
created_at = models.DateTimeField(auto_now_add=True)
MyModel table already exists in the database. price is new field here.
Whenever I start server and create migrations, new migrations are created ‘accounts/migrations/0001_initial.py’.
docker-compose build
docker-compose up -d
docker-compose exec djangoservice bash
~ python manage.py makemigrations
~ python manage.py migrate
after this process, no changes in my database table.
Can someone tell me what am I doing wrong? How can I add new fields in my exesting table?
2
Answers
To get reflect all changes in the local repo that occurred in the docker container's code repository, I added a volume to sync the container with the local repo.
Now build and up the container;
After executing these commands you'll see all migration files will be added to local migration folders. Now commit these files to the version control repo. i.e., git commit .
Maybe you can consider deleting this file manually,I mean 0001_initial.py.
Sometimes migration detection of django is not very effective.