Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8451723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:18:56+00:00 2026-06-10T11:18:56+00:00

I have set PRAGMA foreign_keys=ON; I’m trying to delete some records in a sqlite3

  • 0

I have set PRAGMA foreign_keys=ON;

I’m trying to delete some records in a sqlite3 table and it displays Error: constraint failed

sqlite> delete from auth_user where id = 110;
Error: constraint failed

It works if the PRAGMA foreign_keys was OFF. The database has so many tables and the error is so vague. I think other database systems will list the tables that reference the primary key if we attempt deletion.

What is the efficient way I can find all the tables that reference that particular primary key id=110?

Schema:

CREATE TABLE "auth_user" (
    "id" integer NOT NULL PRIMARY KEY,
    "username" varchar(30) NOT NULL UNIQUE,
    "first_name" varchar(30) NOT NULL,
    "last_name" varchar(30) NOT NULL,
    "email" varchar(75) NOT NULL,
    "password" varchar(128) NOT NULL,
    "is_staff" bool NOT NULL,
    "is_active" bool NOT NULL,
    "is_superuser" bool NOT NULL,
    "last_login" datetime NOT NULL,
    "date_joined" datetime NOT NULL
);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:18:57+00:00Added an answer on June 10, 2026 at 11:18 am

    I don’t think there is a clear-cut way to list the foreign key constraints with SQLite. You can however list all tables with such constraints as shown below. You can then parse the returned SQL to find the constraints.

    Say you have a two parent-child tables:

    sqlite> PRAGMA foreign_keys=ON;
    sqlite> create table Parent (
       ...>     Id INTEGER PRIMARY KEY AUTOINCREMENT, 
       ...>     foo TEXT);
    sqlite> create table Child (
       ...>     Id INTEGER PRIMARY KEY AUTOINCREMENT, 
       ...>     ParentId INTEGER NOT NULL, 
       ...>     bar TEXT,
       ...>     FOREIGN KEY (ParentId) REFERENCES Parent(Id));
    

    You can list the CREATE TABLE statements that have foreign keys:

    sqlite> SELECT sql FROM sqlite_master WHERE sql LIKE '%REFERENCES%';
    CREATE TABLE Child (
        Id INTEGER PRIMARY KEY AUTOINCREMENT, 
        ParentId INTEGER NOT NULL, 
        bar TEXT,
        FOREIGN KEY (ParentId) REFERENCES Parent(Id))
    

    You may already know this, but deleting rows that are constrained some foreign key while foreign keys are turned off kinda breaks referential integrity of the database, so I can only advise you against doing that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing some C# interop work. I have the following struct: #pragma pack(push,1)
I'm trying to export an array of arrays to excel. I have it set
I have some static content on my web site that I have set up
I have set the eclipse java formatter to wrap lines that exceed 120 characters
I have set a background on the data-role=page element like so <div data-role=page style=background:
I have set up Eclipse Indigo to do line debugging with CFEclipse over port
I have set up upload_max_filesize and post_max_size to 32Mb in php.ini. I am using
I have set of flat files (114 files) each file is named with database
I have set the AutoSize property of the form to True and I have
I have set up an app that is registered for remote notifications. - (void)application:(UIApplication*)application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.