Django South 迁移工具与现有应用程序发生错误
我有一个名为 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")
有什么想法吗?
I have existing app named auth
with models and synced db with tables.
I install south
in project settings, run ./manage.py convert_to_south auth
. It successfully created and applied fake migration.
Then i add new model in this app and run ./manage.py schemamigration auth --auto
. And when i was trying to migrate it by run ./manage.py migrate auto
it gives me this massive error:
+ 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")
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
前几天我也遇到了类似的错误。发生这种情况是因为我使用的是MySQL,并且迁移的forwards() 部分不在MySQL 上的事务中运行。这导致我遇到一个问题,无法通过向下迁移然后向上迁移来修复它,因为 South_migrationhistory 表没有注册我最近的迁移。
为了解决这个问题,我使用 --fake 运行 migrate 来获取最新的迁移历史记录。然后,我必须将 try/ except 包装在最新迁移中处理索引的任何内容,并且能够向后运行,然后再次向前运行。
I had a similar error the other day. It happened because I was using MySQL and the forwards() part of the migration doesn't run in a transaction on MySQL. This caused me to have an issue where I couldn't fix it by migrating back down and then up because the south_migrationhistory table didn't register my most recent migration.
To fix this I ran migrate with --fake to get the migration history up to date. Then I had to wrap try/except around anything that dealt with indexes in my latest migration and was able to run backwards and then forwards again.
看起来表
auth_registerticket
已经存在。您是否尝试过删除它并重新应用迁移?Looks like the table
auth_registerticket
already exists. Have you tried dropping it and reapplying the migration?