Artisan command not to lose data from the database

2

Hello, I'm starting to work with laravel 5 and am having a problem when I run the migrate commands the data is lost in the database, is this expected?

The command php artisan migrate works on the first call and the other php artisan refresh and php artisan reset causes the base data to be lost, is there any specific command for it?

    
asked by anonymous 25.02.2016 / 04:31

1 answer

1

If you make changes like adding / deleting a column from some table, it is recommended to create a new migration similar to that

<?php 

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddColumnOwnerToLikes extends Migration
{
    /**
      * Run the migrations.
      *
      * @return void
    */
    public function up()
    {
        Schema::table('likes' , function(Blueprint $table){
        $table->integer('user_id');
    });

}

    /**
      * Reverse the migrations.
      *
      * @return void
    */
    public function down()
    {
     //
    }

}

After creating the migration run the command:

php artisan migrate

soon after execution your new column will be created or deleted.

With the commands:

php artisan migrate:refresh
php artisan migrate:reset

Data will be erased as all tables will be deleted and recreated

    
06.04.2016 / 17:17