我正在研究C#项目,我正在使用system.data.sqlite。我有用
创建的3个(相关)表create table students(
_id integer primary key,
fname text not null,
lname text not null,
st_number integer not null unique,
level integer not null,
class integer,
FOREIGN KEY (class) REFERENCES classes(_id) on delete cascade on update cascade,
FOREIGN KEY (level) REFERENCES levels(_id) on delete cascade on update cascade)
create table payments(
_id integer primary key,
student integer not null,
amount integer not null,
recieve_date text not null,
type text not null,
foreign key(student) references students(st_number) on update cascade on delete cascade)
create table signups(
_id integer primary key,
student integer not null,
service integer not null,
foreign key(student) references students(st_number) on update cascade on delete cascade,
foreign key(service) references services(_id) on update cascade on delete cascade)
现在,当我尝试从学生表中删除记录时,我收到FK违规错误,而我希望它从付款和注册表中删除所有连接的条目。
它可能与我在sqlite中打开FK支持的方式有关。我在我的连接字符串中打开它
@"Data Source=" + dbPath + ";Version=3;foreign_keys = 1;"
很抱歉有很长的创建语句。任何帮助非常感谢。
答案 0 :(得分:0)
@"Data Source=" + dbPath + ";Version=3;foreign_keys = 1;"
看起来是一个错字,应该改为:
@"Data Source=" + dbPath + ";Version=3;foreign keys = 1;"
我将_
更改为空格。
答案 1 :(得分:0)
原来另一张表是指付款而其FK没有级联。补充说,一切正常。