gpt4 book ai didi

python - 在 Django 中进行迁移时发生 TransactionManagementError “Transaction managed block ended with pending COMMIT/ROLLBACK"

转载 作者:行者123 更新时间:2023-12-04 10:37:08 24 4
gpt4 key购买 nike

当我使用 python manage.py migrate manage 进行迁移时(是的,它是 Django 1.8,我无法更改它:/),迁移(我测试过的每一个)总是以相同的错误失败:

django.db.transaction.TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK
enter image description here
这是迁移文件中的代码:
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.... 装饰器。
有人可以帮我吗?

最佳答案

删除迁移文件夹并重新运行迁移
./manage.py makemigrations 应用程序
./manage.py 迁移

或者

您还可以伪造迁移并重置它

关于python - 在 Django 中进行迁移时发生 TransactionManagementError “Transaction managed block ended with pending COMMIT/ROLLBACK",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60116995/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com