从南迁移到django 1.8引发表已经存在

时间:2015-08-22 22:40:05

标签: django django-migrations

我有一个在django 1.6上运行的项目,并努力将其升级到1.8,其中包括从南迁移到django的迁移。

我尝试按照django文档中提到的有关如何从南方更新到django迁移的步骤https://docs.djangoproject.com/en/1.8/topics/migrations/#upgrading-from-south

&安培;在尝试迁移时遇到问题 - 初始假冒,似乎即使有些表存在,django迁移也试图创建它们

./manage.py migrate --fake-initial 


Running migrations:
  Rendering model states... DONE
  Applying retail.0001_initial... FAKED
  Applying contenttypes.0001_initial... FAKED
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0001_initial... FAKED
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying account.0001_initial... FAKED
  Applying default.0001_initial...Traceback (most recent call last):
  File "./manage.py", line 11, in <module>
    execute_from_command_line(sys.argv)
  File "/project-path/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/project-path/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/project-path/lib/python2.7/site-packages/django/core/management/base.py", line 393, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/project-path/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
    output = self.handle(*args, **options)
  File "/project-path/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 222, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/project-path/lib/python2.7/site-packages/django/db/migrations/executor.py", line 110, in migrate
    self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
  File "/project-path/lib/python2.7/site-packages/django/db/migrations/executor.py", line 148, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/project-path/lib/python2.7/site-packages/django/db/migrations/migration.py", line 115, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/project-path/lib/python2.7/site-packages/django/db/migrations/operations/models.py", line 59, in database_forwards
    schema_editor.create_model(model)
  File "/project-path/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 286, in create_model
    self.execute(sql, params or None)
  File "/project-path/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 111, in execute
    cursor.execute(sql, params)
  File "/project-path/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/project-path/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/project-path/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/project-path/lib/python2.7/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "social_auth_association" already exists

有什么建议吗?

的问候,

2 个答案:

答案 0 :(得分:6)

输入python manage.py migrate --help

  

--fake Mark migrations as run without actually running them.

     

--fake-initial Detect if tables already exist and fake-apply initial migrations if so. Make sure that the current database schema matches your initial migration before using this flag. Django will only check for an existing table name.

答案 1 :(得分:5)

来自文档:

唯一的复杂因素是你有一个外键的循环依赖循环;在这种情况下,makemigrations可能会进行多次初始迁移,您需要将它们全部标记为应用:

python manage.py migrate --fake yourappnamehere

所以尝试运行

python manage.py migrate --fake default

它应该可以解决问题。