mercredi 5 octobre 2016

Migrate data from table to different tables with Laravel

I'm working with an existent project on Laravel and I need to change current database schema and keep current data.

For example, I have this table in the initial migration:

Person

----------------------------------------------
| **Id**        |**Name**  | **PhoneNumber** |
----------------------------------------------
|             1 | John Doe | 111-55-5855     |
----------------------------------------------
|             2 | Jane Doe | 111-55-5521     |
----------------------------------------------

But now, I need to split this into two tables:

Person

----------------------------
| **Id**        |**Name**  |
----------------------------
|             1 | John Doe |
----------------------------
|             2 | Jane Doe |
----------------------------

Person Phone

---------------------------------------------------
| **PhoneId**   | **PersonId**  | **PhoneNumber** |
---------------------------------------------------
|             1 |             1 | 111-55-5855     |
---------------------------------------------------
|             2 |             2 | 111-55-5521     |
---------------------------------------------------

So, in the new migration I delete PhoneNumber from Person and add the new table PersonPhone.

Is there any way to map PhoneNumber to the new table and keep PhoneId and PersonId in Person table? Or the only way is create a MySQL script?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire