2015-07-20 206 views
1

我已將我的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 

我該如何解決此問題 - 請幫助!

+0

這是您第一次申請遷移嗎? –

+0

是的,目前還沒有遷移文件。這是全新的安裝 – RunLoop

回答

2

您不應該在服務器上運行makemigrations。您可以在本地,在您的開發機器上執行此操作,並將它們提交到源代碼控制。然後在部署時運行實際的遷移命令。

現在,您可能需要在服務器上刪除並重新創建數據庫,然後重新運行遷移。

2

看起來像你的遷移和數據庫不同步。

嘗試重新創建數據庫,然後運行./manage.py migrate

此外,您不應該在服務器上運行./manage.py makemigrations。看看workflow