问题在服务器上迁移

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了问题在服务器上迁移相关的知识,希望对你有一定的参考价值。

我已将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

我该如何解决-请帮忙!

答案

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

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

另一答案

好像您的迁移和数据库不同步。

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

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

另一答案

您不需要手动升级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兼容。

以上是关于问题在服务器上迁移的主要内容,如果未能解决你的问题,请参考以下文章