Mike
Mike

Reputation: 69

Django Migration questions

I am new to Django, but every time I do any change to the models, I need to do 'python manage.py makemigrations' then 'python manage.py migrate'

makemigrations will create new files under migrations folder:

0001_xx
0002_xx
0003_xx
...

My question is, is this the right way to do it? Because if every time there is a change to the DB model, then a new migration file is created, in the end I could end up having many migration files. Then how to do migration when I want to move to production? Just run the 'python manage.py migrate'?

Upvotes: 1

Views: 167

Answers (2)

Rabeul Hasan
Rabeul Hasan

Reputation: 79

Yes, this is the right way to handle migration files. At the beginning, it may feel little discomfort to see a lot of files created after a certain period of development but it’s ok to have as many migration files created within an app. But Don't try to delete or change any of the migration file because each file has track of what migrations is done before. If it is accidentally deleted, you will face trouble on future migrations. In local server, you may get rid of it easily. But in production, it may come as a nightmare most of the time. OR you may delete all the migrations file except inti.py while pushing code to production but this is not advisable.

Upvotes: 2

user16350436
user16350436

Reputation:

You have to upload all these migrations to the production, or you can simply remove them all (do not remove init.py) and migrate once before pushing the code to the production env.

Upvotes: 0

Related Questions