我正在尝试将查询结果存储到变量中,以便可以在其他查询中使用它,但会出错
# views.py
def post(request):
if request.method == 'POST':
form = newListingForm(request.user, request.POST)
if form.is_valid():
listing = form.save(commit=False)
listing.user = request.user
listing.save()
else:
form = newListingForm(request.user)
return render(request, 'post/post.html', {'form': form})
在编译器日志中获得以下错误:
Unsupported lookup 'user_id' for AutoField or join on the field not permitted.
答案 0 :(得分:3)
在双引号之间插入variable_sku_id
会使标识符名称区分大小写。
删除双引号,应该没问题(我将查询更改为使用ANSI-92语法-将所有内容放在FROM
子句中是过时的Oracle语法,应该避免):
create procedure store_validated_sku_id
(variable_sku_id VARCHAR2)
as
BEGIN
SELECT vsku.SKU_ID INTO store_validated_sku_id.variable_sku_id
FROM vs_sku_discont_details_test discontd
JOIN vsx_dcs_sku vsku
ON discontd.sku_id = vsku.JDA_SKU_ID
JOIN auto_ship_view bcc
ON bcc.sku_id = vsku.SKU_ID
WHERE vsku.web_eligible = 1
AND vsku.discontinued = 0
AND bcc.auto_ship_eligible is null;
END store_validated_sku_id;
答案 1 :(得分:3)
variable_sku_id
用引号引起来(无论是双精度还是单精度,都产生问题),
你应该摆脱他们out
或in out
类型,因为
in
(默认)类型参数不能用作分配目标。答案 2 :(得分:0)
CREATE OR REPLACE PROCEDURE store_validated_sku_id( variable_sku_id OUT VARCHAR2 ) IS
BEGIN
SELECT vsku.SKU_ID
INTO variable_sku_id
FROM vs_sku_discont_details_test discontd
JOIN vsx_dcs_sku vsku
ON discontd.sku_id = vsku.JDA_SKU_ID
JOIN auto_ship_view bcc
ON bcc.sku_id = vsku.SKU_ID
WHERE vsku.web_eligible = 1
AND vsku.discontinued = 0
AND bcc.auto_ship_eligible is null;
END store_validated_sku_id;