Django/南部“;python manage.py migrate caseport“;引发了一个例外

Django/南部“;python manage.py migrate caseport“;引发了一个例外,python,django,django-south,Python,Django,Django South,我正在尝试向现有的Django应用程序添加South支持 我所做的: pip install south Add 'south' to INSTALLED_APPS in settings.py Test that South is now there: $ python manage.py shell Python 2.7.5+ (default, Feb 27 2014, 19:37:08) [GCC 4.8.1] on linux2 Type "help", "copyright", "

我正在尝试向现有的Django应用程序添加South支持

我所做的:

pip install south
Add 'south' to INSTALLED_APPS in settings.py

Test that South is now there:
$ python manage.py shell
Python 2.7.5+ (default, Feb 27 2014, 19:37:08)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import south
>>>

Also, check that South shows up in manage.py help:

python manage.py help

python manage.py syncdb

Make south manage your models:

python manage.py convert_to_south CaseReport

On other instances:
manage.py migrate app_name 0001 --fake

Make your model changes in models.py

Check what -would- happen (dry run):

python manage.py schemamigration CaseReport --auto --stdout

Run it for real:
python manage.py schemamigration CaseReport --auto

Finally:
python manage.py migrate CaseReport
...but this is tracebacking for me.  :(
我得到的回溯是:

$ python manage.py migrate CaseReport
Running migrations for CaseReport:
 - Migrating forwards to 0002_auto__add_field_casereport_date_time_of_last_update.
 > CaseReport:0002_auto__add_field_casereport_date_time_of_last_update
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site-packages/south/management/commands/migrate.py", line 111, in handle
    ignore_ghosts = ignore_ghosts,
  File "/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site-packages/south/migration/__init__.py", line 220, in migrate_app
    success = migrator.migrate_many(target, workplan, database)
  File "/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site-packages/south/migration/migrators.py", line 254, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations, database)
  File "/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site-packages/south/migration/migrators.py", line 329, in migrate_many
    result = self.migrate(migration, database)
  File "/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site-packages/south/migration/migrators.py", line 133, in migrate
    result = self.run(migration, database)
  File "/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site-packages/south/migration/migrators.py", line 111, in run
    if not south.db.db.has_ddl_transactions:
  File "/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site-packages/django/utils/functional.py", line 49, in __get__
    res = instance.__dict__[self.func.__name__] = self.func(instance)
  File "/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site-packages/south/db/generic.py", line 124, in has_ddl_transactions
    if getattr(connection.features, 'supports_transactions', True):
  File "/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site-packages/django/utils/functional.py", line 49, in __get__
    res = instance.__dict__[self.func.__name__] = self.func(instance)
  File "/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 676, in supports_transactions
    self.connection.leave_transaction_management()
  File "/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 322, in leave_transaction_management
    "Transaction managed block ended with pending COMMIT/ROLLBACK")
django.db.transaction.TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK
$python manage.py迁移案例报告
正在为CaseReport运行迁移:
-正向迁移到0002\u自动\u添加\u字段\u案例报告\u日期\u时间\u上次更新。
>案例报告:0002\u自动\u添加\u字段\u案例报告\u日期\u时间\u上次更新的时间
回溯(最近一次呼叫最后一次):
文件“manage.py”,第10行,在
从命令行(sys.argv)执行命令
文件“/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site packages/django/core/management/_init__.py”,第399行,从命令行执行
utility.execute()
文件“/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site packages/django/core/management/_init__.py”,第392行,在execute中
self.fetch_命令(子命令)。从_argv(self.argv)运行_
文件“/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site-packages/django/core/management/base.py”,第242行,从_argv运行
self.execute(*args,**选项._dict__;
文件“/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site packages/django/core/management/base.py”,第285行,执行
输出=self.handle(*args,**选项)
文件“/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site packages/south/management/commands/migrate.py”,第111行,在handle中
忽略重影=忽略重影,
文件“/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site packages/south/migration/_init__.py”,第220行,在migrate_应用程序中
success=migrator.migrate\u many(目标、工作计划、数据库)
文件“/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site packages/south/migration/migrators.py”,第254行,在migrate\u many中
结果=迁移器。\类\迁移\多个(迁移器、目标、迁移、数据库)
文件“/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site packages/south/migration/migrators.py”,第329行,在migrate\u many中
结果=self.migrate(迁移,数据库)
文件“/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site packages/south/migration/migrators.py”,第133行,在migrate中
结果=self.run(迁移、数据库)
文件“/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site packages/south/migration/migrators.py”,第111行,运行中
如果不是south.db.db.has_ddl_事务:
文件“/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site packages/django/utils/functional.py”,第49行,在__
res=instance.\uuuuu dict\uuuuu[self.func.\uuuuuu name\uuuuuuu]=self.func(实例)
文件“/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site packages/south/db/generic.py”,has_ddl_事务中的第124行
如果getattr(connection.features“支持_事务”,True):
文件“/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site packages/django/utils/functional.py”,第49行,在__
res=instance.\uuuuu dict\uuuuu[self.func.\uuuuuu name\uuuuuuu]=self.func(实例)
文件“/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site packages/django/db/backends/_init__.py”,第676行,在supports\u事务中
self.connection.leave\u事务管理()
文件“/home/dstromberg/miniconda/envs/CaseReport/local/lib/python2.7/site packages/django/db/backends/_init__.py”,第322行,在leave_事务管理中
“事务管理块以挂起的提交/回滚结束”)
django.db.transaction.TransactionManagementError:事务管理块以挂起的提交/回滚结束
有人知道我做错了什么吗

我正在Linux Mint 16上使用Django 1.6和Miniconda CPython 2.7.5、South 0.8.4和MySQL 5.5.37-0ubuntu0.13.10.1


谢谢

我也有同样的问题,花了数小时应用不同的解决方案。问题是MySQL用户可能没有操作表的权限,或者数据库中存在回滚测试表。我两者都有,所以也许这会对某人有所帮助:

授予用户对数据库所需的权限,然后刷新权限以生效:

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, INDEX 
    ON `databasename`.* TO 'username'@'ip.address' IDENTIFIED BY 'somepass';
FLUSH PRIVILEGES;
SHOW GRANTS FOR 'username'@'ip.address';
删除表回滚测试(如果有):

USE databasename
DROP TABLE ROLLBACK_TEST;

然后迁移进行得很顺利。

我猜您之前与数据库一起工作过,并且有一个挂起的事务。可能尝试重新启动数据库服务器。您的代码中是否有手动处理事务管理的部分?我使用“sudo service mysql restart”重新启动了mysql,但在运行“python manage.py migrate caseport”时仍然得到了回溯。谢谢你的建议。这很酷,但我评论的第二部分更重要:你的代码中有没有任何地方可以手动管理事务?我现在没有明确使用事务。这些模型看起来如何?谢谢。我完全迷路了,我从未想过要寻找其他用户拥有的表。