1

I am currently working on a Django project with around 30 models and there are lots of relations(For example, foreign key relations) between the models.

My doubt is "After 6 months, let's say I want to add a new field(s) in one of the model/table(s) in models.py, and make migrations, the new migration files will get created without affecting the initial migration files which were created 6 months ago."

Will the relations be maintained after adding new columns in different tables? (or) do I have to go to pgadmin console and tweak them accordingly?

One way is to erase all the migrations and start fresh, but this is not recommended often especially if there is production data (or) there are frequent changes in the database schema.

2 Answers 2

1

@Mahesh, You may use --fake-initial to avoid the existing tables error at the time of new migrations(When you want to add new column).

Relation will be maintained since you already declared it and unless you change it in a new migration.

How to add a new field to a model with new Django migrations?

And in Docs: https://docs.djangoproject.com/en/3.0/ref/django-admin/#cmdoption-migrate-fake-initial

Sign up to request clarification or add additional context in comments.

2 Comments

you mentioned "Relation will be maintained since you already declared it"..........declared what and where can you please elaborate?
@Mahesh, Thanks for your query. I meant that, you already addressed relationship between the models. and you want to add a new column. Since you have lots of models as you mentioned 30. So for new migration which will be occurred due to add a new column to a particular model definitely will not change the other relationship which already exist.
1

If you don't change Django version, adding new fields on models will not create any problem, even after many years. But, there are some situations this might create problems. For example, if Django is updated and you have installed the latest version.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.