Django错误创建新的内容类型

时间:2015-12-07 02:05:06

标签: django postgresql

我在尝试将dev db移动到生产时遇到此错误。 Django dumpdata和loaddata还不够,所以我试图将postgresql的pg_dump转换为.sql文件,然后删除生产数据库并使用命令创建一个新的数据库

sql create database dbname;
sql dbname < dumpfile.sql

该网站现在显示在我的生产服务器上(有一些缺少的css表),数据在数据库中。我无法弄清楚为什么有些css表没有显示(它们在服务器上),当我尝试在我的服务器上运行manage.py migrate时,我得到了这个追溯...

Operations to perform:
  Apply all migrations: contenttypes
Running migrations:
  No migrations to apply.
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 165, in handle
    emit_post_migrate_signal(created_models, self.verbosity, self.interactive, connection.alias)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/sql.py", line 268, in emit_post_migrate_signal
    using=db)
  File "/usr/local/lib/python2.7/dist-packages/django/dispatch/dispatcher.py", line 198, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/management/__init__.py", line 83, in create_permissions
    ctype = ContentType.objects.db_manager(using).get_for_model(klass)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/contenttypes/models.py", line 58, in get_for_model
    " is migrated before trying to migrate apps individually."
RuntimeError: Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually

做了一些搜索,找不到答案,我不知道下一步该转到哪里。

1 个答案:

答案 0 :(得分:0)

它必须与迁移有关我不太确定它是如何工作的,但我的开发版本有一组不同于我的生产(我认为这是正常的,不完全确定??)

所以我在这种情况下要做的就是删除旧数据库,创建新数据库,从生产服务器运行manage.py migrate,然后输入转储的dbdata,一切正常。