How to migrate SQL dump file in Laravel DB Seed

2 years ago


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.

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.