How to deploy migrations to production

192 views
Skip to first unread message

Simon A

unread,
Apr 2, 2019, 8:50:45 AM4/2/19
to Django users
There is a workflow section in the migration page from the django project documentation. But there are somethings I am confused about,

It says that the migrations need to be created in the non production environment and then checked in to the repository along with the changes in models.py.

My question is how would that migration be applied in the production environment.

Once the new migrations and changes in the model are deployed in the server, should I execute python manage.py migrate in the server?

Or is it also acceptable to just deploy the changes in production environment, then execute makemigrations and migrate in production?

FYI, our deployment process is still a bit manual. There is a different person handling the production servers so I'd still have to document the deployment steps and endorse to the sysadmins that will perform the change in the server.

Jani Tiainen

unread,
Apr 2, 2019, 8:59:25 AM4/2/19
to django...@googlegroups.com
Hi.

You should deliver migrations as part of your product and run them on production. Just like you do with collectstatic command you run migrate command.

Eventually you will have data migrations and those you can't recreate on production. Also if you recreate migrations on production again there is not easy way to reproduce same db state locally for debugging purposes.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/35d6d27e-6210-4c8c-b31c-2adb424b9773%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Simon A

unread,
Apr 2, 2019, 8:45:15 PM4/2/19
to Django users
Ah I see. Thank you Jani for clearing that up.

אורי

unread,
Apr 3, 2019, 12:55:31 AM4/3/19
to django...@googlegroups.com
I think makemigrations should never be used in production. You run it locally and then commit the migrations.

If it's a new production server you are deploying, I think you can delete all your migrations and then run makemigrations (locally) to create only initial migrations. But only if you are sure you're not going to need to go back to a previous migration version. But if it's not a new production server, just run migrate there after you commit your migrations locally and pull them from the server.


--

Simon A

unread,
Apr 3, 2019, 1:04:16 AM4/3/19
to Django users
Thank you. I'd surely be able to use this when we deploy. But is it really necessary to run collectstatic everytime there is a deployment to perform? I just use this to make the admin page have the correct styling when accessed in production.


On Wednesday, April 3, 2019 at 12:55:31 PM UTC+8, Uri Even-Chen wrote:
I think makemigrations should never be used in production. You run it locally and then commit the migrations.

If it's a new production server you are deploying, I think you can delete all your migrations and then run makemigrations (locally) to create only initial migrations. But only if you are sure you're not going to need to go back to a previous migration version. But if it's not a new production server, just run migrate there after you commit your migrations locally and pull them from the server.


On Tue, Apr 2, 2019 at 3:51 PM Simon A <arriol...@gmail.com> wrote:
There is a workflow section in the migration page from the django project documentation. But there are somethings I am confused about,

It says that the migrations need to be created in the non production environment and then checked in to the repository along with the changes in models.py.

My question is how would that migration be applied in the production environment.

Once the new migrations and changes in the model are deployed in the server, should I execute python manage.py migrate in the server?

Or is it also acceptable to just deploy the changes in production environment, then execute makemigrations and migrate in production?

FYI, our deployment process is still a bit manual. There is a different person handling the production servers so I'd still have to document the deployment steps and endorse to the sysadmins that will perform the change in the server.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

אורי

unread,
Apr 3, 2019, 6:28:29 AM4/3/19
to django...@googlegroups.com
You can read about collectstatic here:

I think you should run it every time there is a change in the static files. If you want to make sure, run it every time you deploy a new version.


To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages