Deepak Sharma
Deepak Sharma

Reputation: 91

Is there any way to import database directly without using seeding and migration in laravel

i have a import database file called database.sql and i placed that file into my laravel application "database/xyz" directory. i want when my application run first time, all data inserted to connected database.

Thanks

Upvotes: 0

Views: 1496

Answers (1)

Fitzi
Fitzi

Reputation: 1673

You can always run a custom statement in your Laravel application with

DB::statement(" <query here> ");

If your query (or queries, database dumps usually are just a series of queries) lives in a .sql file, there's nothing wrong with reading it from the file. Something like this

DB::statement( file_get_contents('/path/to/your/database.sql') );

Altough your titles says you want to avoid migrations (I assume you basically just want to avoid the schema builder), I still recommend putting this in a migration file, since they exist for exactly that purpose. Also Laravels artisan will make sure that a migration is only run once, so you don't have to handle that yourself.

A simple command will do the job:

php artisan migrate

Upvotes: 1

Related Questions