django - 将数据库从本地 django 迁移到 heroku

标签 django database postgresql heroku migration

我在 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 有一个 ForeignKeycategoria。所以,在本地,我有 3 个数据库:

produtos_produtoprodutos_categoriacliente

我在本地和 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/

相关文章:

python - 无法比较 Postgresql sqlalchemy.exc.ProgrammingError ProgrammingError : (ProgrammingError) can't adapt type 'time.struct_time' 中的日期时间

postgresql - UTF-8 字符的 Postgres 排序

python - 如何在 django 中添加模板 css js 和 bootstrap

django - 如何在django中实现拖放上传文件,而我已经实现了简单的文件上传

database - Nhibernate IList(有序列表)竞争条件

database - Oracle 11g 查询中的标识符无效

postgresql - PG 使用 CTE 和 DML 语句的意外行为

python - Django 管理员 "Edit Selection"操作?

django - 模板中的django slice字符串

mysql - 插入现有表中新添加的列