在服务器

时间:2015-07-20 09:28:50

标签: django postgresql

我已将django项目部署到数字海洋服务器并成功安装了所有要求。但是,当我运行迁移时,在makemigrations之后,我得到以下异常:

django.db.utils.ProgrammingError: relation "auth_permission" already exists

Operations to perform:
  Synchronize unmigrated apps: formtools, django_filters, djcelery, storages
  Apply all migrations: sessions, admin, sites, auth, contenttypes, directory, easy_thumbnails
Synchronizing apps without migrations:
  Creating tables...
    Creating table celery_taskmeta
    Creating table celery_tasksetmeta
    Creating table djcelery_intervalschedule
    Creating table djcelery_crontabschedule
    Creating table djcelery_periodictasks
    Creating table djcelery_periodictask
    Creating table djcelery_workerstate
    Creating table djcelery_taskstate
  Installing custom SQL...
  Installing indexes...
Running migrations:
  Applying contenttypes.0001_initial... FAKED
  Applying auth.0001_initial...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 161, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 68, in migrate
    self.apply_migration(migration, fake=fake)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 102, in apply_migration
    migration.apply(project_state, schema_editor)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/migration.py", line 108, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/operations/models.py", line 36, in database_forwards
    schema_editor.create_model(model)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/schema.py", line 262, in create_model
    self.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/schema.py", line 103, in execute
    cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "auth_permission" already exists

我该如何解决这个问题 - 请帮助!

4 个答案:

答案 0 :(得分:2)

似乎您的迁移和数据库已失去同步。

尝试重新创建数据库,然后运行./manage.py migrate

此外,您不应在服务器上运行./manage.py makemigrations。看看workflow

答案 1 :(得分:2)

您不应该在服务器上运行makemigrations。您可以在开发计算机上本地执行此操作,并将它们提交给源代码管理。然后在部署时运行实际的migrate命令。

目前,您可能需要在服务器上删除并重新创建数据库,然后重新运行迁移。

答案 2 :(得分:0)

最后,我必须删除数据库并按照先前答案中的建议重新创建。

根据我的经验,尽管不建议早晚将迁移文件推送到您的服务器,但这将导致灾难。在服务器本身上运行 makemigrations -这样可以确保数据库的完整性。

答案 3 :(得分:-1)

您不需要手动升级Django-当您使用以下方式更新tendenci时,Django将会与其他依赖项一起自动升级

pip install -r requirements/tendenci.txt --upgrade

或者只是

pip install -r requirements.txt --upgrade

请卸载Django和djcelery,然后运行以上命令。您可能需要伪造djcelery 0001。

python manage.py migrate djcelery 0001 --fake

请注意,tendenci当前与Django 1.8.x兼容。