I have my tables sent directly from laravel, but when I modify some, to add a field or remove it, at the moment of doing the migracion
with laravel, I lose all the data that the tables have, there is some way to make these migrations without losing the data ?, since I did not seem to find anything about it in the official documentation.
Users Table
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->integer('role_id')->unsigned();
$table->string('name');
$table->string('last_name');
$table->integer('ci')->unique();
$table->date('birthdate');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
Schema::table('users', function(Blueprint $table){
$table->foreign('role_id')->references('id')->on('roles');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
Table Roles
class CreateRolesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->char('name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('roles');
}
}