How to update a db without losing data in the tables of these in Laravel?


Every time I need to add a field, another modification I have to execute the php artisan migrate: refresh command but in doing so I update the db but it deletes the data already inserted. Is there a way to avoid that?

asked by Saul Valecillos 19.04.2017 в 19:02

1 answer


The problem is that migrate:refresh , as the name implies, "refreshes" the database, executes all down() of all previously executed migrations and then runs all existing up() migrations.

To add or delete a field or make some other modification to the database (even delete tables, indexes, etc), you just have to create a new migration:

php artisan make:migration agregar_campo_x

In the respective file of the migration you can add a field to an existing table like this:

Schema::table('usuarios', function (Blueprint $table) {

When you have your migration ready, you execute it without additional parameters:

php artisan migrate
answered by 19.04.2017 / 19:08