Running Laravel Migrations on Heroku

Running Laravel Migrations on Heroku

   1 Comment

Migrations are a really handy was of making database changes, be it schema or data, and keeping it in sync across multiple locations. They are however much more useful when automatic, so when they are needed to be run, they run. This helps prevent errors when you forget to run the migrations for instance.

When using platforms like Heroku and tools like Composer, this becomes very easy.

All that’s needed is to add the php artisan migrate --force command (–force is needed because they are run on the production) into the post-install-cmd section of your composer.json. Your entire scripts section will look something like the following:

"scripts": {
    "post-root-package-install": [
        "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    "post-create-project-cmd": [
        "php artisan key:generate"
    "post-install-cmd": [
        "php artisan optimize",
        "php artisan migrate --force",
    "post-update-cmd": [
        "php artisan optimize"

Photo by NATS Press Office


One response to “Running Laravel Migrations on Heroku

  1. Will adding “post-install-cmd” to composer.json overwrite existing data? I want to add a table with migration command but don’t want to drop tables already there. Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *