我在 Heroku 中部署了一个 Django 应用程序。 部署运行良好,但我的模型的数据库没有迁移。
部署后,我再次在本地运行:
python manage.py makemigrations
python manage.py migrate
之后,我做:
heroku run python manage.py makemigrations
heroku run python manage.py migrate
在我运行服务器并等待它运行良好之后:
heroku run python manage.py runserver
我有 3 个模型:
客户、类别、产品
produto
有一个 ForeignKey
到 categoria
。所以,在本地,我有 3 个数据库:
produtos_produto
,produtos_categoria
,cliente
。
我在本地和 heroku 中使用 PostgreSQL
作为数据库。
但是在 heroku 中,我没有任何这样的数据库。
当我运行服务器时,在浏览器中我得到以下答案:
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
最佳答案
您必须在本地运行 makemigrations,然后将生成的迁移文件提交到 git。 Heroku 将在您部署时自动运行。
关于django - 将数据库从本地 django 迁移到 heroku,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35803713/