Гость
Форумы / SQLite [игнор отключен] [закрыт для гостей] / "Error: foreign key mismatch" при попытку удаления всей данных таблицы / 2 сообщений из 2, страница 1 из 1
30.01.2012, 23:40
    #37639155
"Error: foreign key mismatch" при попытку удаления всей данных таблицы
Добрый вечер,
помогите понять поведение SQLite, сборка стандартная, вот лог:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
user@server ~ $ sqlite3 
SQLite version 3.7.7 2011-06-23 19:49:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table t1(i int not null primary key, v varchar(100));
sqlite> create table t2(i int not null primary key, f_i references t1(id));
sqlite> select * from t1;
sqlite> select * from t2;
sqlite> insert into t1(i, v) values(1, 'test');
sqlite> select * from t1 where i = 1;
1|test
sqlite> delete from t1;
sqlite> drop table t1;
sqlite> drop table t2;
sqlite> pragma   foreign_keys = ON;
sqlite> create table t1(i int not null primary key, v varchar(100));
sqlite> create table t2(i int not null primary key, f_i references t1(id));
sqlite> insert into t1(i, v) values(1, 'test');
sqlite> select * from t1;
1|test
sqlite> select * from t2;
sqlite> select * from t1 where i = 1;
1|test
sqlite> ------- What wrong?
sqlite> delete from t1;
Error: foreign key mismatch
sqlite> delete from t1 where i = 1;
Error: foreign key mismatch
sqlite> ------- 
sqlite> drop table t2;
sqlite> delete from t1;
sqlite> 
sqlite> 

т.е. при включенных внешних ключах запрос вида delete from <tablename>; не выполняется несмотря на то, что ссылок на удаляемые данные нет.

сам текст комманд чтобы проверить по-быстрому:

create table t1(i int not null primary key, v varchar(100));
create table t2(i int not null primary key, f_i references t1(id));
select * from t1;
select * from t2;
insert into t1(i, v) values(1, 'test');
select * from t1 where i = 1;
delete from t1;
drop table t1;
drop table t2;
pragma foreign_keys = ON;
create table t1(i int not null primary key, v varchar(100));
create table t2(i int not null primary key, f_i references t1(id));
insert into t1(i, v) values(1, 'test');
select * from t1;
select * from t2;
select * from t1 where i = 1;
------- What wrong?
delete from t1;
delete from t1 where i = 1;
-------
drop table t2;
delete from t1;
...
Рейтинг: 0 / 0
30.01.2012, 23:59
    #37639178
"Error: foreign key mismatch" при попытку удаления всей данных таблицы
Прошу прощения, как всегда виноват сам: f_i references t1(i) вместо f_i references t1(id) имя столбца не совпадало. В заблуждение ввело сообщение об ошибке.

модераторов прошу удалить тему чтобы не засорять форум.
...
Рейтинг: 0 / 0
Форумы / SQLite [игнор отключен] [закрыт для гостей] / "Error: foreign key mismatch" при попытку удаления всей данных таблицы / 2 сообщений из 2, страница 1 из 1
Целевая тема:
Создать новую тему:
Автор:
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]