How to migrate SQL dump file in Laravel DB Seed

How to migrate SQL dump file in Laravel DB Seed

Posted on:May 9, 2020 at 10:00 AM

Hello

Normally we use db:seed in Laravel by faker data. However, today, I will show you how to migrate SQL dump file in Laravel DB Seeder.

Table of Contents

Open Table of Contents

Step 1

Run migration command-

php artisan migrate

Step 2

Download your dump file and paste into database/seeds/source folder.

- database
-- seeds
--- source
---- dump_file

Step 3

Go to database/seeds/DatabaseSeeder.php file and include the dump file to migrate into db inside the run() method.

ini_set('memory_limit', '-1');

\DB::unprepared(file_get_contents(__dir__ . '/source/dump_file'));

** Note**: You can use .sql file in the same way also. In that case, you just need to adjust the file extension.

Step 4

Finally, run the following command-

php artisan db:seed

It should populate data from your dump_file to your database now.

Thanks