Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django south迁移工具与现有应用程序错误_Python_Django_Database Migration_Django South - Fatal编程技术网

Python Django south迁移工具与现有应用程序错误

Python Django south迁移工具与现有应用程序错误,python,django,database-migration,django-south,Python,Django,Database Migration,Django South,我有一个名为auth的现有应用程序,带有模型,并将数据库与表同步。 我在项目设置中安装south,运行/manage.py convert\u to_south auth。它成功创建并应用了假迁移。 然后我在这个应用程序中添加新的模型并运行/manage.py schemamigration auth--auto。当我试图通过运行/manage.py migrate auto迁移它时,它给了我一个巨大的错误: + Added model auth.RegisterTicket Created

我有一个名为
auth
的现有应用程序,带有模型,并将数据库与表同步。 我在项目设置中安装
south
,运行
/manage.py convert\u 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")
+添加了模型验证注册表项
已创建0002\u auto\u add\u registerticket.py。现在,您可以使用:./manage.py migrate auth应用此迁移
nukl MacBook:网站nukl$django migrate auth
正在运行身份验证迁移:
-正向迁移到0002\u自动添加\u注册表项。
>认证:0002\u自动\u添加\u注册表项
! 在迁移的实际运行期间发现错误!流产。
! 因为您的数据库不支持运行
! 在事务中改变模式的语句,我们有
! 使其在迁移之间处于过渡状态。
! 您*可能*能够通过:=删除表'auth\u registerticket'级联进行恢复;[]
! 南方开发商对此感到遗憾,并将
! 喜欢温柔地劝你稍微考虑一下。
! 更容易处理DBMS。
! 注意:导致迁移失败的错误还在后面。
回溯(最近一次呼叫最后一次):
文件“manage.py”,第11行,在
执行\u管理器(设置)
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site packages/django/core/management/__init__.py”,第438行,在execute_manager中
utility.execute()
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site packages/django/core/management/_init___;.py”,第379行,在execute中
self.fetch_命令(子命令)。从_argv(self.argv)运行_
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py”,第191行,运行时从_argv开始
self.execute(*args,**选项._dict__;
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site packages/django/core/management/base.py”,第220行,在execute中
输出=self.handle(*args,**选项)
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site packages/South-0.7.3-py2.7.egg/South/management/commands/migrate.py”,句柄中的第105行
忽略重影=忽略重影,
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site packages/South-0.7.3-py2.7.egg/South/migration/________.py”,第191行,在migrate_应用程序中
success=migrator.migrate\u many(目标、工作计划、数据库)
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site packages/South-0.7.3-py2.7.egg/South/migration/migrators.py”,第221行,在migrate\u中
结果=迁移器。\类\迁移\多个(迁移器、目标、迁移、数据库)
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site packages/South-0.7.3-py2.7.egg/South/migration/migrators.py”,第292行,在migrate\u中
结果=self.migrate(迁移,数据库)
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site packages/South-0.7.3-py2.7.egg/South/migration/migrators.py”,migrate中的第125行
结果=self.run(迁移)
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site packages/South-0.7.3-py2.7.egg/South/migration/migrators.py”,第99行,运行中
返回self.run\u迁移(迁移)
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site packages/South-0.7.3-py2.7.egg/South/migration/migrators.py”,第81行,运行时迁移
迁移函数()
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site packages/South-0.7.3-py2.7.egg/South/migration/migrators.py”,第57行
返回(λ:方向(orm))
文件“/migrations/0002\u auto\u add\u registerticket.py”,第16行,向前
('user',self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.user']),
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site packages/South-0.7.3-py2.7.egg/South/db/generic.py”,第226行,在create_表格中
“,”。联接([col for columns in columns if col]),
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site packages/South-0.7.3-py2.7.egg/South/db/generic.py”,执行中第150行
cursor.execute(sql,params)
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site packages/django/db/backends/util.py”,执行中的第15行
返回self.cursor.execute(sql,params)
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site packages/django/db/backends/mysql/base.py”,执行中的第86行
返回self.cursor.execute(查询,参数)
文件“build/bdist.macosx-10.6-intel/egg/MySQLdb/cursors.py”,执行中第174行
文件“build/bdist.macosx-10.6-intel/egg/MySQLdb/connections.py”,第36行,在defaulterrorhandler中
_mysql_exceptions.OperationalError:(1050,“表'auth_registerticket'已存在”)

有什么想法吗?

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

前几天我遇到了类似的错误。这是因为我使用的是MySQL,迁移的forwards()部分没有在MySQL上的事务中运行。这导致我出现了一个问题,我无法通过先向下再向上迁移来修复它,因为south_migrationhistory表没有注册我最近的迁移


为了解决这个问题,我运行了migrate with--fake以更新迁移历史记录。然后,我不得不将try/except与我最新迁移中处理索引的内容打包,并能够前后运行。

以上是说明。你试过了吗?什么说明?如何删除已创建的表?