-1

I've made a migration in a folder and when I run php artisan migrate nothing happens. I do not want to specify a certain folder every time to run migrations so I am not sure what the error is.

I do not see the migration in the migrations table. here are some outputs

php artisan make:migration create_<whatever>_table --path='/database/migrations/<MyFolderName>/'

   INFO  Created migration [2022_08_23_090654_create_<whatever>_table].

php artisan migrate

   INFO  Nothing to migrate.

php artisan migrate:status

  Migration name ............................................. Batch / Status
  2019_12_14_000001_create_personal_access_tokens_table ...... [6] Ran
  2021_09_01_145427_create_users_table ....................... [5] Ran
  2021_09_01_145441_create_<another1_table>_table ............ [5] Ran
  2021_09_01_145452_create_<another2_table>_table ............ [5] Ran
  2021_09_01_145927_create_<another3_table>_table ............ [6] Ran
  2021_09_01_150555_create_<another4_table>_table ............ [6] Ran

ODelibalta
  • 2,194
  • 1
  • 18
  • 28

1 Answers1

0

If the additional paths you use are knowable beforehand you can add the following in one of your service providers (e.g. in AppServiceProvider):

app()->make('migrator')->path(database_path('migrations/<MyFolderName>/'));

This should make your migrator (the class that is responsible for running migrations) to also look in the given path for new migrations.

As @ODelibalta pointed out there is a method that can simplify this in the ServiceProvider class already:

$this->loadMigrationsFrom([database_path().'/migrations/<FolderName>']);

Running the above in any service provider should work and may be preferable because it deffers resolving the migrator until it's needed.

apokryfos
  • 38,771
  • 9
  • 70
  • 114
  • Thank you for this exactly what I needed. What do you think about this ```$this->loadMigrationsFrom([database_path().'/migrations/']);``` in `AppServiceProvider` boot method – ODelibalta Aug 23 '22 at 14:40
  • I was not aware of that method. It looks like it uses something similar to register migration paths so it looks better than what I originally suggested – apokryfos Aug 23 '22 at 14:47