- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试获取具有一组特定 FK 字段的 ValuesQuerySet,这些 FK 字段跨越多个表之间的关系。当我在 django shell 中运行此查询时,甚至没有打嗝。但是,当在开发服务器上运行时,Django 会在一些(但不是全部)这些 FK 字段上返回 FieldDoesNotExist 错误。
以下是相关模型(我使用的是标准 Django 用户模型):
class Profile(models.Model):
user = models.OneToOneField(User)
first_name = models.CharField(max_length=150,null=True)
middle_name = models.CharField(max_length=150,null=True)
last_name = models.CharField(max_length=150,null=True)
headline = models.TextField(null=True)
connections = models.ManyToManyField('self',through="Connection",symmetrical=False,related_name="connections+")
status = models.CharField(max_length=15,default="active")
class Position(models.Model):
entity = models.ForeignKey(Entity,related_name="positions")
person = models.ForeignKey(User,related_name="positions")
careers = models.ManyToManyField("Career",related_name="positions")
title = models.CharField(max_length=150,null=True)
summary = models.CharField(max_length=450,null=True)
description = models.TextField(null=True)
current = models.BooleanField(default=True)
start_date = models.DateField(null=True)
end_date = models.DateField(null=True)
type = models.CharField(max_length=450,null=True)
degree = models.CharField(max_length=450,null=True)
field = models.CharField(max_length=450,null=True)
status = models.CharField(max_length=15,default="active")
created = models.DateTimeField(auto_now_add=True, null=True)
updated = models.DateTimeField(auto_now=True, null=True)
class Entity(models.Model):
name = models.CharField(max_length=450)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
status = models.CharField(max_length=15,default="active")
class Picture(models.Model):
person = models.ForeignKey(Profile,related_name="pictures")
pic = models.ImageField(max_length=450,upload_to=_get_picture_path)
source = models.CharField(max_length=45,null=True)
description = models.TextField(null=True)
license = models.TextField(null=True)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
status = models.CharField(max_length=15,default="active")
在一个 View 中,我运行两个略有不同的查询来获取一部分用户以及从这些连接表中提取的信息(一个仅限于一组用户 ID,user_ids
):
some_people = User.objects.values('id','profile__headline','profile__first_name','profile__last_name','profile__pictures__pic','positions__entity__id','positions__entity__name').filter(id__in=user_ids).annotate(no_of_pos=Count('positions__id')).order_by('-no_of_pos')
all_people = User.objects.select_related('positions','profile').values('id','profile__headline','profile__first_name','profile__last_name','profile__pictures__pic','positions__entity__id','positions__entity__name').annotate(no_of_pos=Count('positions__id')).order_by('-no_of_pos')
这些功能几乎相同,一个仅限于一组预定义的用户(由 id 标识),另一个则不是。我知道这些结果会返回某些信息的重复项,但我会在稍后的步骤中处理这一点,当我将这些信息组装到略有不同的模板字典中时
如果我在 shell 中运行这些查询,则没有问题。查询不会花费任何时间,并且所有字段都会得到正确评估。但是,开发服务器返回此错误:
User has no field named 'headline'
只要包含“profile_headline”、“profile_pictures_pic”、“positions_entity_name”,就会返回类似的错误。这个错误对我来说没有任何意义。这些字段确实存在,但不在用户对象上——而且它们永远不会在用户对象上调用。另外,为什么只有这些字段? “profile_last_name”、“profile__first_name”和“positions_entity_id”在我看来应该都属于同一个容器。
请帮我解决这个问题——有什么想法吗?
我在 Mac OS X 上运行 Django 1.4.2 和 Python 2.6。
最佳答案
发生的情况是您在开发服务器上拥有的模型定义与您拥有的物理数据库模式不匹配。可能是因为您添加了新字段但尚未迁移它们。
要检查,请运行 ./manage.py migrate --list
。如果是这种情况,开发服务器上的迁移应该可以解决问题。
关于python - Django 在服务器上返回 FieldDoesNotExist 错误但在 shell 中传递正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15034509/
Github:https://github.com/jjvang/PassIntentDemo 我一直在关注有关按 Intent 传递对象的教程:https://www.javacodegeeks.c
我有一个 View ,其中包含自动生成的 text 类型的 input 框。当我单击“通过电子邮件发送结果”按钮时,代码会将您带到 CalculatedResults Controller 中的 Em
我有一个基本的docker镜像,我将以此为基础构建自己的镜像。我没有基础镜像的Dockerfile。 基本上,基本镜像使用两个--env arg,一个接受其许可证,一个选择在容器中激活哪个框架。我可以
假设我想计算 2^n 的总和,n 范围从 0 到 100。我可以编写以下内容: seq { 0 .. 100 } |> Seq.sumBy ((**) 2I) 但是,这与 (*) 或其他运算符/函数不
我有这个网址: http://www.example.com/get_url.php?ID=100&Link=http://www.test.com/page.php?l=1&m=7 当我打印 $_G
我想将 window.URL.createObjectURL(file) 创建的地址传递给 dancer.js 但我得到 GET blob:http%3A//localhost/b847c5cd-aa
我想知道如何将 typedef 传递给函数。例如: typedef int box[3][3]; box empty, *board[3][3]; 我如何将 board 传递给函数?我
我正在将一些代码从我的 Controller 移动到核心数据应用程序中的模型。 我编写了一个方法,该方法为我定期发出的特定获取请求返回 NSManagedObjectID。 + (NSManagedO
为什么我不能将类型化数组传递到采用 any[] 的函数/构造函数中? typedArray = new MyType[ ... ]; items = new ko.observableArray(ty
我是一名新的 Web 开发人员,正在学习 html5 和 javascript。 我有一个带有“选项卡”的网页,可以使网页的某些部分消失并重新出现。 链接如下: HOME 和 JavaScript 函
我试图将对函数的引用作为参数传递 很难解释 我会写一些伪代码示例 (calling function) function(hello()); function(pass) { if this =
我在尝试调用我正在创建的 C# 项目中的函数时遇到以下错误: System.Runtime.InteropServices.COMException: Operation is not allowed
使用 ksh。尝试重用当前脚本而不修改它,基本上可以归结为如下内容: `expr 5 $1 $2` 如何将乘法命令 (*) 作为参数 $1 传递? 我首先尝试使用“*”,甚至是\*,但没有用。我尝试
我一直在研究“Play for Java”这本书,这本书非常棒。我对 Java 还是很陌生,但我一直在关注这些示例,我有点卡在第 3 章上了。可以在此处找到代码:Play for Java on Gi
我知道 Javascript 中的对象是通过引用复制/传递的。但是函数呢? 当我跳到一些令人困惑的地方时,我正在尝试这段代码。这是代码片段: x = function() { console.log(
我希望能够像这样传递参数: fn(a>=b) or fn(a!=b) 我在 DjangoORM 和 SQLAlchemy 中看到了这种行为,但我不知道如何实现它。 最佳答案 ORM 使用 specia
在我的 Angular 项目中,我最近将 rxjs 升级到版本 6。现在,来自 npm 的模块(在 node_modules 文件夹内)由于一些破坏性更改而失败(旧的进口不再有效)。我为我的代码调整了
这个问题在这里已经有了答案: The issue of * in Command line argument (6 个答案) 关闭 3 年前。 我正在编写一个关于反向波兰表示法的 C 程序,它通过命
$(document).ready(function() { function GetDeals() { alert($(this).attr("id")); } $('.filter
下面是一个例子: 复制代码 代码如下: use strict; #这里是两个数组 my @i =('1','2','3'); my @j =('a','b','c'); &n
我是一名优秀的程序员,十分优秀!