2011-03-10 53 views
0

我有現有的應用程序名爲auth與模型和同步數據庫與表。 我在項目設置中安裝south,運行./manage.py convert_to_south auth。它成功創建並應用了僞造的遷移。 然後,我在這個應用程序中添加新模型,並運行./manage.py schemamigration auth --auto。當我試圖通過運行./manage.py migrate auto遷移它,它給了我這個巨大的錯誤:Django南遷移工具與現有的應用程序錯誤

+ 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

說明如上。你試過了嗎? – gladysbixly 2011-03-10 16:09:18

+0

有什麼指示?如何刪除創建的表? – nukl 2011-03-11 03:15:52

回答

0

看起來像表auth_registerticket已經存在。您是否嘗試刪除它並重新應用遷移?

2

我有一個類似的錯誤有一天。發生這種情況是因爲我使用的是MySQL,並且遷移的forwards()部分沒有在MySQL的事務中運行。這導致我遇到了一個問題,即無法通過遷移回遷再恢復,因爲south_migrationhistory表未註冊我最近的遷移。

爲了解決這個問題,我運行了-fake來遷移歷史記錄。然後,我必須包裝嘗試/除了在我最近的遷移中處理索引的任何事情,並且能夠向後運行然後再轉發。