How to use php artisan migrate command of Laravel4 in Heroku?
Asked Answered
F

7

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

Fustanella answered 27/11, 2013 at 13:7 Comment(8)
When you run the artisan migrate command, how your terminal looks? What does it write?Rodriquez
Nothing to migrate. But I think command is running on running on local machine.Fustanella
Did you create your migration files? (artisan migrate:make)Rodriquez
No I did not run that command. Do I need to run that? what it doesFustanella
You should read this chapter of the documentation (and the Schema builder one's too).Rodriquez
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" CreateUserTableFustanella
let us continue this discussion in chatFustanella
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.Raymundorayna
S
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

Samarasamarang answered 30/1, 2014 at 15:47 Comment(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'Fustanella
Maybe they change it recently, but I had to do this: heroku run php /app/artisan migratePepperandsalt
M
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".

Mathur answered 15/5, 2014 at 14:8 Comment(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.Mutule
S
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

Samarasamarang answered 30/1, 2014 at 15:47 Comment(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'Fustanella
Maybe they change it recently, but I had to do this: heroku run php /app/artisan migratePepperandsalt
W
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

Winze answered 24/5, 2016 at 4:42 Comment(0)
C
6

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

heroku run php artisan
Cellar answered 31/12, 2014 at 16:50 Comment(0)
T
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.

Thursby answered 28/12, 2019 at 8:40 Comment(1)
This answer makes a lot of sense. It allows me to run Linux commands and execute artisan quite wellLevins
D
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

Dekow answered 28/1, 2016 at 9:40 Comment(0)
D
0

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

Dx answered 10/9, 2022 at 14:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.