Home > Back-end >  Django Migration questions
Django Migration questions

Time:09-29

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'?

CodePudding user response:

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 files 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.

CodePudding user response:

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.

  • Related