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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:19:15+00:00 2026-05-16T04:19:15+00:00

what is wrong with this alter table command : ALTER TABLE `lp` ADD COLUMN

  • 0

what is wrong with this alter table command :

ALTER TABLE `lp` 
ADD COLUMN `RuleId` INT(10) NOT NULL DEFAULT -111 AFTER `Weight` , , 
ADD CONSTRAINT `fk_1` FOREIGN KEY (`RuleId` ) REFERENCES `Rules` (`RuleId` ) ON DELETE NO ACTION ON UPDATE NO ACTION,
ADD INDEX `fk_1` (`RuleId` ASC) ;

if i drop the line

  ADD CONSTRAINT `fk_1` FOREIGN KEY (`RuleId` ) REFERENCES `Rules` (`RuleId` ) ON DELETE NO ...

its work ,

the error i get is :

Error Code : 1005
Can't create table '..' (errno: 121)

how can i add a FOREIGN KEY and INDEX on the same field ?

Update:

i try to separate to 2 queries, first add INDEX and after that add FOREIGN KEY, the index added but the second query do not work !

when i change the name of foreign key (like : ‘fk_2’) and try run it i get an error : Error Code : 1452 Cannot add or update a child row: a foreign key constraint fails

  • 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-16T04:19:16+00:00Added an answer on May 16, 2026 at 4:19 am

    First create the index and second the foreign key constraint. MySQL needs an index to create the foreign key, that’s why you have to create the index first. Use seperate statements as well.

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

Sidebar

Related Questions

What is wrong with this query? ALTER TABLE KARGO ADD COLUMN test VARCHAR(100) NOT
Does anyone see why I'm getting this error on this simple command? alter table
In Oracle 10i, I'm running the following command: ALTER TABLE jnrvwchnglst ADD ( jnrvwchnglst_userid
I am trying to add a column into mysql table using this query but
There is something wrong with this trigger. But what? CREATE TRIGGER MYCOOLTRIGGER AFTER INSERT
Why is this wrong? <table> <form> <tr><td>something something</td/> </form> </table> I'm talking about position
i have two tables: CREATE TABLE public.auctions ( id VARCHAR(255) NOT NULL, auction_value_key VARCHAR(255)
I'm not sure whts wrong with this code... else if (combo_View.Text == Orders) {
I am having trouble with a ALTER TABLE command that I am trying to
I want to add a default constraint to a existing table. So i use

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.