django dumpdata =>在heroku上加载

时间:2015-05-10 09:31:37

标签: django postgresql heroku

我正在尝试将数据从我的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_... 

可能是什么问题?

1 个答案:

答案 0 :(得分:2)

stacktrace的结尾有键:

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