Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrate databases from local django to heroku

I have an application in Django that I deploy in heroku. The deploy works well, but my model's database was not migrate.

After the deploy, I run again localy:

python manage.py makemigrations
python manage.py migrate

After, I do:

heroku run python manage.py makemigrations
heroku run python manage.py migrate

And after I run the server and wait it works well:

heroku run python manage.py runserver

I have 3 models:

cliente, categoria, produto

produto has a ForeignKey to categoria. So, localy, I have 3 databases:

produtos_produto, produtos_categoria, cliente.

I use PostgreSQL as database localy and in heroku.

But in heroku, I don't have any of this databases.

When I run the server, in browser I have the following answer:

ProgrammingError at /

relation "produtos_categoria" does not exist
LINE 1: ...ia"."descricao", "produtos_categoria"."logo" FROM "produtos_...
                                                             ^

Request Method:     GET
Request URL:    http://redewebsite.herokuapp.com/
Django Version:     1.9.2
Exception Type:     ProgrammingError
Exception Value:    

relation "produtos_categoria" does not exist
LINE 1: ...ia"."descricao", "produtos_categoria"."logo" FROM "produtos_...
                                                             ^

Exception Location:     /app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils.py in execute, line 64
Python Executable:  /app/.heroku/python/bin/python
Python Version:     2.7.11
Python Path:    

['/app',
 '/app/.heroku/python/bin',
 '/app/.heroku/python/lib/python2.7/site-packages/setuptools-19.6-py2.7.egg',
 '/app/.heroku/python/lib/python2.7/site-packages/pip-8.0.2-py2.7.egg',
 '/app',
 '/app/.heroku/python/lib/python27.zip',
 '/app/.heroku/python/lib/python2.7',
 '/app/.heroku/python/lib/python2.7/plat-linux2',
 '/app/.heroku/python/lib/python2.7/lib-tk',
 '/app/.heroku/python/lib/python2.7/lib-old',
 '/app/.heroku/python/lib/python2.7/lib-dynload',
 '/app/.heroku/python/lib/python2.7/site-packages']

Server time:    Sex, 4 Mar 2016 17:50:43 +0000
like image 613
dsbonafe Avatar asked Mar 04 '16 18:03

dsbonafe


1 Answers

You must run makemigrations locally, then commit those generated migration files to git. Heroku will run then automatically when you deploy.

like image 195
Daniel Roseman Avatar answered Oct 27 '22 01:10

Daniel Roseman