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? Commented Nov 27, 2013 at 13:11
  • Nothing to migrate. But I think command is running on running on local machine. Commented Nov 27, 2013 at 13:16
  • Did you create your migration files? (artisan migrate:make) Commented Nov 27, 2013 at 13:19
  • No I did not run that command. Do I need to run that? what it does Commented Nov 27, 2013 at 13:21
  • You should read this chapter of the documentation (and the Schema builder one's too). Commented 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".

Sign up to request clarification or add additional context in comments.

1 Comment

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

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'
Maybe they change it recently, but I had to do this: heroku run php /app/artisan migrate
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

Comments

6

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

heroku run php artisan

Comments

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 Comment

This answer makes a lot of sense. It allows me to run Linux commands and execute artisan quite well
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

Comments

0

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.