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?
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?
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) {
$table->string('direccion');
});
When you have your migration ready, you execute it without additional parameters:
php artisan migrate