【发布时间】:2020-05-23 19:11:22
【问题描述】:
当我使用 python manage.py migrate manage 进行迁移时(是的,它是 Django 1.8,我无法更改它:/),迁移(我测试的每一个)总是失败并出现相同的错误:
django.db.transaction.TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK
这是迁移文件中的代码:
class Migration(SchemaMigration):
def forwards(self, orm):
# Check expiry keys in Organization
for org in Organization.objects.all():
self.checkExpiryDate(org)
# Check expiry keys in UserProfileRoleInOrganization
for uprio in UserProfileRoleInOrganization.objects.all():
self.checkExpiryDate(uprio)
def checkExpiryDate(self, entity):
# Check if expiry_date is consistent with apikey and fix it if necessary
if not entity.date_has_changed:
return
date_in_key = entity.getExpiryDateInKey()
if not date_in_key:
return
y = int(date_in_key[:4])
m = int(date_in_key[4:-2])
d = int(date_in_key[-2:])
entity.expiry_date = datetime.datetime(y,m,d)
entity.save()
def backwards(self, orm):
pass
我已经看到其他类似问题的一些答案,但不,我的代码中没有任何 @commit.... 装饰器。
有人可以帮帮我吗?
【问题讨论】:
-
什么是
SchemaMigration? -
数据迁移中如何声明Organization和UserProfileRoleInOrganization?
-
@nima 这是来自 south.v2 的 South 模型,但我检查过,它继承自 BaseMigration,但几乎不是空的
-
@MarioOrlandi 如果这是您要求的,我只是做了两个“导入”声明。我知道他们工作正常
-
我会回复一个正确的答案,以便有一些可用的格式;)
标签: python django migration django-south