M
M
Muhammad2016-02-23 10:19:43
Laravel
Muhammad, 2016-02-23 10:19:43

Is it correct to enter data directly from migrations?

For example, I create a table with roles and I immediately need to add several roles there. Or I add a new role to a table already filled with some data. Create posts directly from migrations? In this case, the migrations become too large. What is the best way to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
JhaoDa, 2016-02-23
@muhammad_97

There is no clear answer here. But in general, you can follow the following logic:
- if this is test data, then do it in seeds;
- if this is real data for the application to work, then either in migrations, or write a console command that will enter this data. Similar to seeds, but already within the application, with checks of different conditions (the current environment, for example).
My last two projects are porting applications from WordPress to Laravel and I created console commands and import mechanisms from csv / xml, and filled in small amounts of role types in migrations.

S
Stanislav Pochepko, 2016-02-23
@DJZT

For this there are seeds Tyk

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question