首页 > 解决方案 > 芹菜,关系“x_x”不存在

问题描述

查询期间 Celery 出现问题

这是我的代码:

from apps.teams.models import Team

@shared_task
@transaction.atomic
def createUserTenant():

    addUserInTeam = Team.objects.create(user_id = 1)

这是错误:

return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "teams_team" does not exist
LINE 1: INSERT INTO "teams_team" ("user_id") VALUES (1) RETURNING "t...

由于将相同的查询移动到我的视图时一切正常,但在芹菜中工作正常

标签: pythoncelery

解决方案


固定的 :

我必须选择当前模式,因为 celery 默认选择公共模式

with schema_context(current_schema):
    addUserInTeam = Team.objects.create(user = CustomUser.objects.get(pk=userid))

推荐阅读