You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

创建含外键的SQLite表触发语法错误,寻求问题排查方案

SQLite外键语法错误修正

你的外键定义存在语法错误,SQLite中外键引用的正确格式是:
FOREIGN KEY (当前表的外键列) REFERENCES 关联表名(关联表的对应列)

你错误地给关联表名email_html加上了括号,并且把关联列的位置写反了,导致SQL解析失败。

修正后的完整SQL脚本如下:

drop table if exists enviada;

create table if not exists enviada 
(
    destinatario_email varchar(300),
    destinatario_nome varchar(200),
    destinatario_cpf_cnpj varchar(14),
    data_envio datetime,
    remetente varchar(50),
    assunto varchar(200),
    foreign key (assunto) references email_html(assunto),
    primary key (destinatario_email, destinatario_cpf_cnpj, data_envio, assunto)
);

注意:执行前要确保email_html表已存在,且该表中确实有名为assunto的列,否则会出现关联失败的错误。

内容的提问来源于stack exchange,提问作者Clodoaldo Pinto

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 16:02:46