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 8104391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:49:32+00:00 2026-06-05T23:49:32+00:00

this insert fails on my db – insert into tig_pairs (pkey, pval, uid) select

  • 0

this insert fails on my db –

insert into tig_pairs (pkey, pval, uid) select 'schema-version', '4.0', uid from tig_users where (sha1_user_id = sha1(lower('db-properties')));
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`tigasedb`.`tig_pairs`, CONSTRAINT `tig_pairs_constr_2` FOREIGN KEY (`nid`) REFERENCES `tig_nodes` (`nid`))

Where table definitions are:

create table if not exists tig_pairs (
   nid int unsigned,
   uid int unsigned NOT NULL,

   pkey varchar(255) NOT NULL,    
   pval mediumtext,

   PRIMARY KEY (nid, pkey),      --        ***
             key pkey (pkey),
         key uid (uid),
         key nid (nid),
         constraint tig_pairs_constr_1 foreign key (uid) references tig_users (uid),
         constraint tig_pairs_constr_2 foreign key (nid) references tig_nodes (nid)
)
ENGINE=InnoDB default character set utf8 ROW_FORMAT=DYNAMIC;

and

create table if not exists tig_nodes (
   nid int unsigned NOT NULL auto_increment,
   parent_nid int unsigned,
   uid int unsigned NOT NULL,

   node varchar(255) NOT NULL,

   primary key (nid), 
   unique key tnode (parent_nid, uid, node),
   key node (node),
         key uid (uid),
         key parent_nid (parent_nid),
         constraint tig_nodes_constr foreign key (uid) references tig_users (uid)
)
ENGINE=InnoDB default character set utf8 ROW_FORMAT=DYNAMIC;

The line PRIMARY KEY (nid, pkey), -- ***gets omitted, then my query goes through just fine. Is there a conflict between that primary key and the troubling foreign key constraint ? How can I avoid it ? The primary key has to stay there 🙂

Thanks!

EDIT: got rid of the error by changing the tig_pairs definition on one line:

nid int unsigned NOT NULL auto_increment,
  • 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-05T23:49:34+00:00Added an answer on June 5, 2026 at 11:49 pm

    You have a foreign constraint on your tig_pairs table referencing the tig_nodes table. However, you are not inserting any data into tis nid field. The referenced field, tig_nodes.nid, doesn’t allow NULL values. Due to these two constraints, you cannot INSERT null into the nid field of tig_pairs.

    See also this question: MySQL foreign key to allow NULL?

    Edit: also, primary key values are never allowed to be NULL; so as long as nid is included in that primary key, you cannot make it NULL.

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

Sidebar

Related Questions

this is how insert into, select is usually working (example taken from: https://stackoverflow.com/a/576442/101055 ):
I wrote this query: INSERT INTO KeysTable (KeyText, Id) SELECT KeyText as BKT, KeysTable.ID
I have this select insert into test(t_name) (select users.first_name || '_' || users.last_name ||
This works: INSERT INTO people (`name`, `job`) values ('Bob', 'sales') but this fails: INSERT
If I try this statement: INSERT INTO TerminalEventChild (id,stringValue) VALUES (64,'version123|'); MySQL fail with
what i am trying to do is this: INSERT INTO Table1 (id1, id2) (
I have an insert query that gets generated like this INSERT INTO InvoiceDetail (LegacyId,InvoiceId,DetailTypeId,Fee,FeeTax,Investigatorid,SalespersonId,CreateDate,CreatedById,IsChargeBack,Expense,RepoAgentId,PayeeName,ExpensePaymentId,AdjustDetailId)
Is it possible to do something like this: INSERT INTO table(col1, col2) VALUES(something_from_another_table, value);
im trying to insert this query with mysql_query INSERT INTO um_group_rights (`um_group_id`,`cms_usecase_id`,`um_right_id`) VALUES (2,1,1)
I have this code: cursor = conn.cursor() cursor.execute((insert into new_files (videos_id, filename, is_processing) values

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.