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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:48:27+00:00 2026-05-17T22:48:27+00:00

I have two tables: Table Author: ID (INTEGER), author_name (VARCHAR), first_name (VARCHAR), last_name (VARCHAR),

  • 0

I have two tables:

Table Author:
ID (INTEGER),
author_name (VARCHAR),
first_name (VARCHAR),
last_name (VARCHAR),
preferred_name (VARCHAR).

Table CoAuthored:
ID (INTEGER)
author1ID (INTEGER),
author2ID (INTEGER),
paper_ID (INTEGER) (ID of the co-authored paper referenced by this link)

I want to add foreign key constraints such that author1ID and author2ID in CoAuthored refer to ID in Author. I defined the tables as such:

CREATE TABLE Author(ID INT, author_name VARCHAR(100), preferred_name VARCHAR(100), first_name VARCHAR(100), last_name VARCHAR(100), PRIMARY KEY(ID)) ENGINE=INNODB;

CREATE TABLE CoAuthored(ID INT, author1ID INT, author2ID INT, paper_ID INT);

This is my attempt at creating the foreign key:

ALTER TABLE CoAuthored ADD foreign key (author1ID) references Author(ID) on delete cascade on update cascade;

This executes just fine, but when I try to add a a tuple which contains an author1ID that doesn’t exist in ID, it allows me to do it, meaning the foreign key constraint isn’t working.

What do I need to do differently? I tried making both tables ENGINE=INNODB in the create statements, but then I’d get an ERROR 1005 can’t create table.

  • 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-05-17T22:48:28+00:00Added an answer on May 17, 2026 at 10:48 pm

    from: https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-6035435.html

    In order to set up a foreign key relationship between two MySQL tables, three conditions must be met:

    1. Both tables must be of the InnoDB table type.

    2. The fields used in the foreign key relationship must be indexed.

    3. The fields used in the foreign key relationship must be similar in data type.

    Important: For non-InnoDB tables, the FOREIGN KEY clause is ignored.

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

Sidebar

Related Questions

I have two tables: articles and articletags articles: id, author, date_time, article_text articletags: id,
I have a relationship between two tables, authors and styles. Every author is associated
I have two tables: Table 1: ID, PersonCode, Name, Table 2: ID, Table1ID, Location,
I have two tables: a source table and a target table. The target table
I have two tables in my database: NEWS table with columns: id - the
I have two identical tables and need to copy rows from table to another.
I have two simple tables in my database. A card table that contains Id,
I have a one to many relationship between two tables. The many table contains
I have two tables Table : 1, Name : NdcAwp, Columns-Ndc, AwpUnitCost Table :
I have two tables Table Visitor ID Name CityName 1 Jon NY 1 Jon

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.