21

I am suing Heroku dev plan for creating database using PostgreSQL. Database is created in Heroku. After running heroku pg:info command

$ heroku pg:info
=== HEROKU_POSTGRESQL_XXX_URL
Plan:        Hobby-dev
Status:      available
Connections: 1
PG Version:  9.3.1
Created:     2013-11-27 04:00 UTC
Data Size:   6.4 MB
Tables:      0
Rows:        0/10000 (In compliance)
Fork/Follow: Unsupported
Rollback:    Unsupported

Result shows zero tables, which is correct.

In my local machine tables are created by using following command which are supported in Laravel4 framework.

php artisan migrate

php artisan db:seed

But it seems like I cannot run this command in heroku to create table and dump data. Please tel me how can I create a copy of my local database in Heroku.

Thanks all

8
  • When you run the artisan migrate command, how your terminal looks? What does it write? Nov 27, 2013 at 13:11
  • Nothing to migrate. But I think command is running on running on local machine.
    – niran
    Nov 27, 2013 at 13:16
  • Did you create your migration files? (artisan migrate:make) Nov 27, 2013 at 13:19
  • No I did not run that command. Do I need to run that? what it does
    – niran
    Nov 27, 2013 at 13:21
  • You should read this chapter of the documentation (and the Schema builder one's too). Nov 27, 2013 at 13:25

7 Answers 7

64

with the new official php buildpack you just run

$ heroku run bash
$ php artisan migrate

or just

$ heroku run php artisan migrate

And if you want the migration to happen every time you deploy via git then add "php artisan migrate" to to composer.json in the "post-update-cmd" section of "scripts".

1
  • I suggest you to use the "post-install-cmd" section instead. "post-update-cmd" will be called only when running composer update. You don't want to run composer update in production.
    – Deric Lima
    May 1, 2020 at 5:42
15

It took a little digging, but I was able to use it by running this command:

heroku run /app/php/bin/php /app/www/artisan migrate

So the lesson I learned was this: prefix all remote artisan commands with heroku run /app/php/bin/php /app/www/artisan

2
  • not worked for me :) got this error. bash: -c: line 0: syntax error near unexpected token (' bash: -c: line 0: C:/Program Files (x86)/Git/app/php/bin/php C:/Program Files (x86)/Git/app/www/artisan migrate'
    – niran
    Apr 25, 2014 at 20:42
  • 3
    Maybe they change it recently, but I had to do this: heroku run php /app/artisan migrate Apr 29, 2014 at 20:25
7

Here is a complete example, and will solve "nothing to migrate issue" that comes in for Heroku,

heroku run php artisan migrate --path=database/migrations --app application-name

application-name is your Heroku APP name

6

This line will give you access to all laravel artisan commands:

heroku run php artisan
3

If you have multiple applications on a heroku server, you can do:

heroku run bash -a application-name

this will open a bash container for that specific application, and you can run any command inside this container. i.e

php artisan migrate:refresh --seed

Obviously you'll first need to make sure that you are already logged in to the heroku cli.

1
  • This answer makes a lot of sense. It allows me to run Linux commands and execute artisan quite well Apr 8, 2022 at 17:19
1

I would recommend to run migration as a part of build process. As it should be. Take a look at https://github.com/lifekent/heroku-buildpack-laravel. Official build pack with easy yo use support for running artisan commands

0

heroku run php artisan migrate -a {your app name}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.