Hello I have a database already created with some tables and records in them, this database was previously created with laravel.
Now what happens is that it was necessary to modify some relationships between the tables from the laravel miagraciones and new tables were added with relations to those that were already.
So I want to know if you could make the migration of the new tables and update the new relationship between tables without deleting the records of the tables that are already created.
for example
mysql> select * from users;
+----+----------------------------+------------------------------+--------------+----------+--------------+------------+--------------------------------------------------------------+---------------------+---------------------+
| id | name | email | telphone | password | profesion_id | company_id | remember_token | created_at | updated_at |
+----+----------------------------+------------------------------+--------------+----------+--------------+------------+--------------------------------------------------------------+---------------------+---------------------+
| 1 | Juan Carlos | [email protected] | 573102184475 | | 2 | 2 | NULL | 2017-05-18 16:22:39 | 2017-05-24 13:47:17 |
| 2 | JUan | [email protected] | NULL | | 1 | 1 | WkYYlmlZq4HVphmo1ZIcKMYd7WlYIliumg2ZqFhENzaJC3ccyJUIkap0KL2S | 2017-05-18 16:23:24 | 2017-05-18 16:23:24 |
+----+----------------------------+------------------------------+--------------+----------+--------------+------------+--------------------------------------------------------------+---------------------+---------------------+
I have the table users that is related to the table roles the relationship is many to many
+----+------+---------------+---------------------+---------------------+
| id | name | description | created_at | updated_at |
+----+------+---------------+---------------------+---------------------+
| 1 | adm | Administrador | 2017-05-18 16:22:06 | 2017-05-18 16:22:06 |
| 2 | opr | Operador | 2017-05-18 16:22:06 | 2017-05-18 16:22:06 |
| 3 | usr | Usuario | 2017-05-18 16:22:06 | 2017-05-18 16:22:06 |
+----+------+---------------+---------------------+---------------------+
that's why this other table exists
+----+---------+--------+------------+------------+
| id | user_id | rol_id | created_at | updated_at |
+----+---------+--------+------------+------------+
| 1 | 1 | 3 | NULL | NULL |
| 3 | 2 | 1 | NULL | NULL |
| 4 | 2 | 2 | NULL | NULL |
| 5 | 2 | 3 | NULL | NULL |
| 6 | 3 | 1 | NULL | NULL |
| 8 | 5 | 3 | NULL | NULL |
| 9 | 4 | 1 | NULL | NULL |
| 10 | 6 | 3 | NULL | NULL |
| 11 | 7 | 3 | NULL | NULL |
| 12 | 8 | 3 | NULL | NULL |
| 13 | 9 | 3 | NULL | NULL |
| 14 | 10 | 3 | NULL | NULL |
+----+---------+--------+------------+------------+
where the roles are related to the users
then the user's migration is this
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->text('name',100);
$table->string('email',191)->unique();
$table->string('telphone', 12)->nullable();
$table->string('password')->nullable();
$table->integer('profesion_id')->unsigned();
$table->foreign('profesion_id')->references('id')->on('profesion_cliente');
$table->integer('company_id')->unsigned();
$table->foreign('company_id')->references('id')->on('company');
$table->rememberToken();
$table->timestamps();
});
but then the two change or update that will be done is the following:
The migration should be like this
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->text('name',100);
$table->string('email',191)->unique();
$table->string('telphone', 12)->nullable();
$table->string('password')->nullable();
$table->integer('profesion_id')->unsigned();
$table->foreign('profesion_id')->references('id')->on('profesion_cliente');
$table->string('url')->nullable();
$table->integer('rol_id')->unsigned();
$table->foreign('rol_id')->references('id')->on('roles');
$table->rememberToken();
$table->timestamps();
});
A new field was added and a relationship was removed.
Then those fields are wanted but no need to delete all user records.