usging django 2.0.2 python3.4 drf
详细信息跳过
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'main',
'USER': 'root',
'PASSWORD': 'root123',
'HOST': 'localhost',
'PORT': "3309",
'OPTIONS': {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
'charset': 'utf8mb4',
'use_unicode': True,
}
},
'log': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'log',
'USER': 'root',
'PASSWORD': 'root123',
'HOST': 'localhost',
'PORT': "3309"
}
}
models.py
#used database main
class Post(models.Model):
PostUID = models.BigAutoField(
db_column='PostUID', primary_key=True)
logmodels.py
#used database log
class PostLog(models.Model):
LogUID = models.BigAutoField(
db_column='LogUID', primary_key=True)
#top directory is main
PostUID = models.ForeignKey(
"main.Post", db_column='PostUID', on_delete=models.CASCADE)
UserUID = models.ForeignKey ... skip
我试过这段代码
Post.objects.all().annotate(Log=Case(When(postlog__UserUID=request.get("UserUID"),then=1), output_field=IntegerField(), default=Value(0)))
提高此例外
django.db.utils.ProgrammingError: (1146, "Table 'main.Postlog' doe
sn't exist")
如果创建或让我使用objects.using("log")
工作
如何在orm中使用