Load Data in Database outside testing fixtures

Is possibile to load fixture data inside database, outside testing ?
I need to populate my db with some data … but i want do it in the cakephpway

Are you using the Migrations plugin to build your database? If so then check out Seeds:
https://book.cakephp.org/migrations/3/en/index.html#seed-seeding-your-database

I also just insert some records directly from the migration script itself, I think Seeds are designed to be able to run over and over again.

If you don’t use the plugin then I guess writing a Shell/Console Command is the way to go.

1 Like

I’m with @deanoj, seeding is the way to go.

Also check out this link to the phinx documentation with special attention to this section on seeding and this very useful bit about the Faker library.

It will be well worth your effort.

1 Like

Ohh great ! thank you soo much :slight_smile:

While you’re wandering in the land of fixtures and the creation of test data you will also want to keep this FixtureFactory link handy. This is an excellent alternative to the built in cake testing fixtures.

If you’re project requires a lot of nuanced data for testing, this tool will help keep you from being bogged down understanding and maintaining large fixture data sets. There are some videos in the documentation to give you an idea of how things work.