May Sale! All accounts are 40% off this week.

jonaspauleta's avatar

Database schema changes to production

Hello,

Imagine you have an app running on production already, then you made some changes to your mysql db, for example, adding one column to an already existing table, how would I make that change on the production database without losing my data?

Thanks.

0 likes
1 reply
Nakov's avatar

By creating a new migration which updates the table: https://laravel.com/docs/8.x/migrations#updating-tables

you would make sure you either add a nullable column or a column with a default value which all the other rows will inherit.

Make sure you make a backup as well, and that's it. But the critical part of the migration is when you create the table Schema::create is used when updating Schema::table is used. And of course you will test locally with existing data. But as long as you are updating the table, no data will be lost, that's the benefit of the migrations as well.

Please or to participate in this conversation.