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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:51:29+00:00 2026-06-03T20:51:29+00:00

I have two tables I have created and I’m adding the foreign key constraint

  • 0

I have two tables I have created and I’m adding the foreign key constraint after the fact.

The two tables are defined as such:

CREATE TABLE `user` (
  `user_id` int(11) NOT NULL auto_increment,
  `user_ad_id` varchar(500) default NULL,
  `user_name` varchar(100) NOT NULL,
  `login_id` varchar(100) default NULL,
  `email` varchar(256) NOT NULL,
  `personal_config` int(10) NOT NULL,
  PRIMARY KEY  (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

and

CREATE TABLE IF NOT EXISTS personal_config (
    config_id INT(10) NOT NULL AUTO_INCREMENT,
    last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    configuration TEXT(25600) NOT NULL,
    PRIMARY KEY (config_id)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE personal_config ADD CONSTRAINT personal_config_fk_user FOREIGN KEY 
(config_id) REFERENCES user(personal_config);

And I keep getting the same error but can’t figure it out. I’ve searched all the related threads to this.

  • 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-03T20:51:30+00:00Added an answer on June 3, 2026 at 8:51 pm

    Your ALTER TABLE statement is backward. Since personal_config.config_id is an auto_increment primary key, the foreign key should be defined in the users table against personal_config, not in personal_config against the users table.

    ALTER TABLE users ADD CONSTRAINT user_fk_personal_config 
       FOREIGN KEY (personal_config)
       REFERENCES personal_config(config_id);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables A and B as defined bellow. create table A (
I have created two tables ORDERS and ORDERITEMS with the following constraint: alter table
I have two tables that I'd like to create a foreign key for. Primary
I have two tables: codes_tags and popular_tags. codes_tags CREATE TABLE `codes_tags` ( `code_id` int(11)
I have two tables: entitytype and project . Here are the create table statements:
So I have two tables structured like so: CREATE TABLE #nodes(node int NOT NULL);
I have two SQL statements: CREATE TABLE legs(legid INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
I have two tables like this create table A_DUMMY ( TRADE_ID VARCHAR2(16) TRADE_DATA VARCHAR2(500)
I have two tables in my database that look like this CREATE TABLE IF
I have two tables t1 and t2. i have created two triggers tr1 after

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.