首页 > 数据库 >20240722-0725 数据库外键报错

20240722-0725 数据库外键报错

时间:2024-07-25 15:42:35浏览次数:9  
标签:product 0725 name 报错 user file join 20240722 id

数据库关联查询:

​ 有一个村庄表,每个村庄属于一个村庄管理员,存着村庄管理员的id,村庄管理员在user_user和sys_user里存着。

​ 查询村庄表,是超级管理员能看到所有村庄,村庄管理员只能看到自己的村庄。

select 
v.id, v.name, v.owner_id, v.created_at, v.updated_at 
from location_village v 
join user_user u on v.owner_id = u.id 
left join sys_user su on su.TEL = u.phone 
where ${USER_ID} in (select user_id from sys_user_role where role_id = 'root') 
or su.USER_ID = ${USER_ID}

由于需要条件查询,所以需要sys_user,sys_user只和user_user关联,所以需要join两个表。

select 
p.id, p.name, p.price, p.unit, f.file, 
p.description, p.is_on_sale, p.is_reviewed, 
a.name as area_name, u.name as user_name, pc.name as category_name, 
p.created_at, p.updated_at, su.USER_ID, p.area_id, p.merchant_id, 
p.category_id, pi.file_id 
from product_product p 
left join product_product_image pi on p.id = pi.product_id 
left join backstage_file f on pi.file_id = f.id 
join location_area a on p.area_id = a.id 
join user_user u on p.merchant_id = u.id 
join product_productcategory pc on p.category_id = pc.id 
join sys_user su on u.phone = su.TEL 
报错:
'set' object is not subscriptable

错误原因:我把返回数据写成return {'xx'}了,只有键没有值

An error occurred: list index out of range

“list index out of range”这个错误通常发生在尝试访问列表中不存在的索引时。比如,如果你的列表只有5个元素,但你尝试访问第6个元素(索引为5的元素,因为索引是从0开始的),就会出现这个错误。

图片id存在列表中,我没有上传图片,列表为空。

An error occurred: string indices must be integers

这个错误信息 "string indices must be integers" 指的是在Python中,你尝试使用非整数类型的索引来访问字符串中的元素。在Python中,字符串是一个序列,它的索引必须是整数。

例如,如果你有一个字符串 s = "hello",你可以使用 s[0] 来访问第一个字符 'h',因为0是一个整数。如果你尝试使用非整数类型的索引,比如 s["first"],Python就会抛出这个错误。

要解决这个问题,你需要确保你用来访问字符串索引的是整数。如果你的代码中有变量用作索引,检查这个变量确保它是整数类型。如果需要,你可以使用 int() 函数将索引转换为整数。

错误原因:我之前写了一个处理列表的工具,列表的数据是一个个字典,现在想处理字典,没有修改就用了,里边有一个for item in result,result是一个字典,所以就报错了。

3780 - Referencing column fileid' and referenced column 'file id' in foreign key constraint product_product image_fileid_e43b9flc_fk_backstage_fileid' are incompatible.

在尝试创建外键约束时遇到了问题。具体来说,外键约束中引用的列名和被引用的列名不兼容。

这里的问题很可能是列名的命名不一致导致的。在外键约束中,引用的列(即子表中的列)和被引用的列(即父表中的列)必须具有完全相同的名称和数据类型。

这是在navicat中创建外键时的错误,被引用的字段我是手打的,报了这个错误,后来手动选择,又报了另一个错误:

1091 - Can't DROP 'product_product jimage_file_id_e43b9f1c_ fk_backstage_file_id'; check that column/key exists

刷新了几遍就好了。。。

创建新外键又报了错误:

3780 - Referencing column file id' and referenced column file id' in foreign key constraint 'product_produce jimage _file id' are incompatible.

错误原因:外键类型错了,一个是int,一个是bigint

修改了类型,还是报错,原因:两个表中的数据不匹配,把数据全删了就好了。

标签:product,0725,name,报错,user,file,join,20240722,id
From: https://www.cnblogs.com/marverdol/p/18323293

相关文章