Reputation: 375
I have designed a database using mysql workbench and synchronize, then my mysql database exists @ phpmyadmin . then how can I use this database with laravel.. I mean I need to create migration files for existing database and continue editing..
Upvotes: 2
Views: 4255
Reputation: 179
My situation was the following:
After trying everything, I decided to walk the extra mile and solve my problem like this:
I created a method in a temporary controller. Basically, it checks through all my migration classes in database/migrations folder and then checks if they exist in the migrations table. If not, insert them into the table. Called the method from the browser and now everything is synched
public function syncMigration(){
$migrations_folder = database_path('migrations');
$filesInFolder = File::files($migrations_folder);
$lastMigration = DB::table('migrations')->orderBy('batch', 'desc')->limit(1)->first();
var_dump($lastMigration);
$batch = $lastMigration->batch +1;
foreach($filesInFolder as $path) {
$file = pathinfo($path);
$migration = DB::table('migrations')->where('migration', $file['filename'])->first();
if(!$migration){
DB::table('migrations')->insert(
[
'migration' => $file['filename'],
'batch' => $batch
]
);
}
}
}
Upvotes: 0
Reputation: 845
while in developing stage you can use : https://github.com/awssat/laravel-sync-migration
by using :
php artisan migrate:sync
but I won't recommend use it for production since you can't track the migrations changes
Upvotes: 0
Reputation: 559
You could you this package Migrations Generator
php artisan migrate:generate
to generate the migrations for all the tables in you current database. To generate the migrations for specific tables, run php artisan migrate:generate table1,table2,table3,table4,table5
.Upvotes: 0
Reputation: 439
You should write the migration files, so your schema can be built from zero without a manual intervention. But if you can't or you don't want to do it, you can start your migrations from your desired point:
php artisan make:migration blablabla
Write the new schema and:
php artisan migrate
And so on.
Upvotes: 2