python - Foreign Key Constraint Failed in Sqlite3 -


i'm executing script second time(these tables exist previously) , getting foreign key constraint failed error. i'm beginner in sqlite3 , not able figure out cause behind it.

schema.sql

pragma foreign_keys = 1;  drop table if exists user; create table user(uid integer primary key autoincrement,  username text not null, password text not null, email text not null, isadmin integer default 0);  drop table if exists asset; create table asset(aid integer primary key autoincrement, assetname text not null, releasedate text, owner integer default 0, isreserved integer default 0, foreign key(owner) references user(uid) on delete set default); 

i'm reading file in python script.

error:

traceback (most recent call last):   file "<stdin>", line 1, in <module>   file "main.py", line 37, in create_table     conn.cursor().executescript(f.read()) sqlite3.integrityerror: foreign key constraint failed 

when dropping table, effect same if deleting rows, , these deletions can fail.

drop tables first, , in correct order (asset first).


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -