我有一个名为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")
有什么想法吗?
答案 0 :(得分:2)
前几天我有类似的错误。之所以发生这种情况,是因为我使用MySQL而且迁移的forwards()部分不会在MySQL上的事务中运行。这导致我遇到一个问题,我无法通过向下迁移然后向上迁移来修复它,因为south_migrationhistory表没有注册我最近的迁移。
要解决此问题,我使用--fake运行迁移以使迁移历史记录保持最新状态。然后我不得不将try / except包装在我最近迁移中处理索引的任何内容中,并且能够向后运行然后再向前运行。
答案 1 :(得分:0)
看起来表auth_registerticket
已经存在。您是否尝试过删除它并重新应用迁移?