20

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

Chris Travers
  • 25,424
  • 6
  • 65
  • 182
niran
  • 1,920
  • 8
  • 34
  • 60
  • When you run the artisan migrate command, how your terminal looks? What does it write? – Fractaliste Nov 27 '13 at 13:11
  • Nothing to migrate. But I think command is running on running on local machine. – niran Nov 27 '13 at 13:16
  • Did you create your migration files? (artisan migrate:make) – Fractaliste Nov 27 '13 at 13:19
  • No I did not run that command. Do I need to run that? what it does – niran Nov 27 '13 at 13:21
  • You should read [this chapter](http://laravel.com/docs/migrations) of the documentation (and the Schema builder one's too). – Fractaliste Nov 27 '13 at 13:25
  • wait.. I ran this command during application setup. that is the reason i can see the table created in LOCAL db. Now i want run this command on deployed applicaton. this the command used. php artisan migrate:make --table="user" CreateUserTable – niran Nov 27 '13 at 13:28
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/42037/discussion-between-niran-and-fractaliste) – niran Nov 27 '13 at 13:32
  • I think you need to just run the migrate command if you already made the migrations before pushing up to heroku. In rails you run it through 'heroku run' like 'heroku run rake db:migrate' so I would guess in Laravel it would be 'heroku run php artisan db:migrate' See if that works. – isimmons Dec 15 '13 at 02:30

7 Answers7

63

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".

danronmoon
  • 3,814
  • 5
  • 34
  • 56
dwenaus
  • 3,206
  • 2
  • 27
  • 27
  • 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 01 '20 at 05: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

Aaron Gustafson
  • 602
  • 6
  • 11
  • 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 '14 at 20:42
  • 3
    Maybe they change it recently, but I had to do this: heroku run php /app/artisan migrate – Hernan Rajchert Apr 29 '14 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

Alen MJ
  • 136
  • 1
  • 5
6

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

heroku run php artisan
Roshan Pal
  • 7,438
  • 2
  • 12
  • 12
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.

usmany
  • 146
  • 2
  • 11
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

lifekent
  • 170
  • 6
0

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

RickyS
  • 11
  • 2