0

我有auth以模型命名的现有应用程序,并将数据库与表同步。我south在项目设置中安装,运行./manage.py convert_to_south auth. 它成功创建并应用了虚假迁移。然后我在这个应用程序中添加新模型并运行./manage.py schemamigration auth --auto。当我试图通过运行迁移它时,./manage.py migrate auto它给了我这个巨大的错误:

 + Added model auth.RegisterTicket
Created 0002_auto__add_registerticket.py. You can now apply this migration with: ./manage.py migrate auth
nukl-MacBook:website nukl$ django migrate auth
Running migrations for auth:
 - Migrating forwards to 0002_auto__add_registerticket.
 > auth:0002_auto__add_registerticket
 ! Error found during real run of migration! Aborting.

 ! Since you have a database that does not support running
 ! schema-altering statements in transactions, we have had 
 ! to leave it in an interim state between migrations.

! You *might* be able to recover with:   = DROP TABLE `auth_registerticket` CASCADE; []

 ! The South developers regret this has happened, and would
 ! like to gently persuade you to consider a slightly
 ! easier-to-deal-with DBMS.
 ! NOTE: The error which caused the migration to fail is further up.
Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_manager(settings)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/South-0.7.3-py2.7.egg/south/management/commands/migrate.py", line 105, in handle
    ignore_ghosts = ignore_ghosts,
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/South-0.7.3-py2.7.egg/south/migration/__init__.py", line 191, in migrate_app
    success = migrator.migrate_many(target, workplan, database)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/South-0.7.3-py2.7.egg/south/migration/migrators.py", line 221, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations, database)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/South-0.7.3-py2.7.egg/south/migration/migrators.py", line 292, in migrate_many
    result = self.migrate(migration, database)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/South-0.7.3-py2.7.egg/south/migration/migrators.py", line 125, in migrate
    result = self.run(migration)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/South-0.7.3-py2.7.egg/south/migration/migrators.py", line 99, in run
    return self.run_migration(migration)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/South-0.7.3-py2.7.egg/south/migration/migrators.py", line 81, in run_migration
    migration_function()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/South-0.7.3-py2.7.egg/south/migration/migrators.py", line 57, in <lambda>
    return (lambda: direction(orm))
  File "/migrations/0002_auto__add_registerticket.py", line 16, in forwards
    ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])),
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/South-0.7.3-py2.7.egg/south/db/generic.py", line 226, in create_table
    ', '.join([col for col in columns if col]),
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/South-0.7.3-py2.7.egg/south/db/generic.py", line 150, in execute
    cursor.execute(sql, params)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/util.py", line 15, in execute
    return self.cursor.execute(sql, params)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 86, in execute
    return self.cursor.execute(query, args)
  File "build/bdist.macosx-10.6-intel/egg/MySQLdb/cursors.py", line 174, in execute
  File "build/bdist.macosx-10.6-intel/egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
_mysql_exceptions.OperationalError: (1050, "Table 'auth_registerticket' already exists")

有任何想法吗?

4

2 回答 2

2

前几天我遇到了类似的错误。发生这种情况是因为我使用的是 MySQL,并且迁移的 forwards() 部分没有在 MySQL 上的事务中运行。这导致我遇到一个问题,我无法通过向下迁移然后向上迁移来解决它,因为 south_migrationhistory 表没有注册我最近的迁移。

为了解决这个问题,我使用 --fake 运行了 migrate 以获取最新的迁移历史记录。然后我不得不将 try/except 包裹在我最近的迁移中处理索引的任何东西上,并且能够向后运行,然后再次向前运行。

于 2011-03-10T16:13:55.527 回答
0

看起来该表auth_registerticket已经存在。您是否尝试过删除它并重新应用迁移?

于 2011-03-10T15:51:13.557 回答