5

Well, I do have a package take I only use alongside with my system. I do have migrations for that package (it was build on Laravel 4.2, and I'm upgrading it).

That being said: On my package (former workbench) on Laravel 5.1, where do I put and how do I run my migrations?

Does any of you guys know how to deal with this?

UPDATE:

This is not the case of a simple migration. Back on laravel 4.*, we were able to maintain migrations for each package (if it was so desirable), and I do have some migrations been held by my own package, in it's own database, with it's own table. So... I need it to be a PACKAGE's migrations and not a ROOT INSTALATION's migration.

Dennis Braga
  • 1,448
  • 3
  • 20
  • 40

3 Answers3

4

You can put it in packages/.../src/migrations. To run it:

  1. You can insert in composer.json :

"autoload": { "classmap": [ "database", "packages/.../src/migrations" ],

  1. Or just call :

    • Laravel 4.x php artisan migrate --package="{vendor}/{name}"
    • Laravel 5.x php artisan migrate --path=/packages/.../migrations

For more info : check this blog from websanova.com

4givN
  • 2,936
  • 2
  • 22
  • 51
  • I accidentally upvoted this answer even though it didn't work for me. This other one did: https://stackoverflow.com/a/50499101/470749 – Ryan May 24 '18 at 00:06
2

Updated Answer for Laravel 5.6+

https://laravel.com/docs/5.6/packages#migrations says:

If your package contains database migrations, you may use the loadMigrationsFrom method to inform Laravel how to load them. The loadMigrationsFrom method accepts the path to your package's migrations as its only argument:

/**
 * Perform post-registration booting of services.
 *
 * @return void
 */
public function boot()
{
    $this->loadMigrationsFrom(__DIR__.'/path/to/migrations');
}

Once your package's migrations have been registered, they will automatically be run when the php artisan migrate command is executed. You do not need to export them to the application's main database/migrations directory.

The forward-slash is important. In my case, I used: $this->loadMigrationsFrom(__DIR__ . "/migrations");.

Ryan
  • 22,332
  • 31
  • 176
  • 357
-1

To create a migration:

  1. Go to command prompt locate your project root folder and run this command: php artisan make:migration yourMigrationFileName --create=tableName
  2. You can found your migration file in yourProjectFolder\database\migrations\timestamp_yourMigrationFileName.php
  3. Create your table.

To run the migration:

  1. Go to command prompt locate your project root folder and run this command: php artisan migrate

And don't forget to declare your table name in your Model. You can do it by writing protected $table = 'tableName' in your model.

smartrahat
  • 5,381
  • 6
  • 47
  • 68