【问题标题】:django dumpdata => load on herokudjango dumpdata => 在heroku上加载
【发布时间】:2015-07-20 21:41:25
【问题描述】:

我正在尝试将数据从我的 sqlite 数据库加载到 heroku postgres,但它不工作。

首先我跑了:

manage.py dumpdata --indent 1 > data.json

然后我尝试将它上传到heroku(在我将文件提交到heroku之后):

heroku run python manage.py loaddata data.json

但它只是没有工作......

它给了我错误:

Running `python manage.py loaddata data.json` attached to terminal... up, run.92
01
Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/_
_init__.py", line 385, in execute_from_command_line
utility.execute()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/_
_init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/b
ase.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/b
ase.py", line 338, in execute
output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/c
ommands/loaddata.py", line 61, in handle
self.loaddata(fixture_labels)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/c
ommands/loaddata.py", line 91, in loaddata
self.load_label(fixture_label)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/c
ommands/loaddata.py", line 148, in load_label
obj.save(using=self.using)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/serializers/
base.py", line 173, in save
models.Model.save_base(self.object, using=using, raw=True)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.py
", line 617, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, upda
te_fields)
  File "/app/.heroku/python/lib/python2.7/sitepackages/django/db/models/base.py
", line 679, in _save_table
forced_update)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.py
", line 723, in _do_update
return filtered._update(values) > 0
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.p
y", line 600, in _update
return query.get_compiler(self.db).execute_sql(CURSOR)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/com
piler.py", line 1004, in execute_sql
cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/com
piler.py", line 786, in execute_sql
cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils
.py", line 65, in execute
return self.cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py",     line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils
.py", line 65, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: Problem installing fixture '/app/data.json': C
ould not load contenttypes.ContentType(pk=1): relation "django_content_type"     does not exist
LINE 1: UPDATE "django_content_type" SET "name" = 'log entry', "app_... 

可能是什么问题?

【问题讨论】:

标签: django postgresql heroku


【解决方案1】:

stacktrace的末尾有key:

relation "django_content_type"     does not exist
LINE 1: UPDATE "django_content_type" SET "name" = 'log entry', "app_... 

django_content_type 不存在。尝试运行迁移:

heroku run python manage.py migrate

或者,如果您使用的是旧版本:

heroku run python manage.py setupdb

【讨论】:

  • 在运行loaddata 之前,我已经运行了makemigrationsmigrate,但它仍然会触发问题。它在本地与 SQLite 一起工作。
  • 您需要在本地运行python manage.py makemigrations,提交新的迁移,并将它们推送到heroku。您还需要提交给 repo 的任何固定装置。然后你可以运行heroku run python manage.py migrate 来迁移Heroku 数据库,运行loaddata 来加载fixture。 heroku run X 命令不能创建文件,它们只能处理已经提交和推送的文件。
猜你喜欢
  • 2021-02-04
  • 2021-12-08
  • 2018-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多