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

  • Home
  • SEARCH
  • 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 8908283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:08:21+00:00 2026-06-15T03:08:21+00:00

I got this error when i was trying to alter my table. Error Code:

  • 0

I got this error when i was trying to alter my table.

Error Code: 1833. Cannot change column 'person_id': used in a foreign key constraint 'fk_fav_food_person_id' of table 'table.favorite_food'

Here is my CREATE TABLE STATEMENT Which ran successfully.

CREATE TABLE favorite_food(
    person_id SMALLINT UNSIGNED,
    food VARCHAR(20),
    CONSTRAINT pk_favorite_food PRIMARY KEY(person_id,food),
    CONSTRAINT fk_fav_food_person_id FOREIGN KEY (person_id)
    REFERENCES person (person_id)
);

Then i tried to execute this statement and i got the above error.

ALTER TABLE person MODIFY person_id SMALLINT UNSIGNED 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-15T03:08:22+00:00Added an answer on June 15, 2026 at 3:08 am

    The type and definition of foreign key field and reference must be equal.
    This means your foreign key disallows changing the type of your field.

    One solution would be this:

    LOCK TABLES 
        favorite_food WRITE,
        person WRITE;
    
    ALTER TABLE favorite_food
        DROP FOREIGN KEY fk_fav_food_person_id,
        MODIFY person_id SMALLINT UNSIGNED;
    

    Now you can change you person_id

    ALTER TABLE person MODIFY person_id SMALLINT UNSIGNED AUTO_INCREMENT;
    

    recreate foreign key

    ALTER TABLE favorite_food
        ADD CONSTRAINT fk_fav_food_person_id FOREIGN KEY (person_id)
              REFERENCES person (person_id);
    
    UNLOCK TABLES;
    

    EDIT:
    Added locks above, thanks to comments

    You have to disallow writing to the database while you do this,
    otherwise you risk data integrity problems.

    I’ve added a write lock above

    All writing queries in any other session than your own ( INSERT, UPDATE, DELETE ) will wait till timeout or UNLOCK TABLES; is executed

    http://dev.mysql.com/doc/refman/5.5/en/lock-tables.html

    EDIT 2: OP asked for a more detailed explanation of the line “The type and definition of foreign key field and reference must be equal. This means your foreign key disallows changing the type of your field.”

    From MySQL 5.5 Reference Manual: FOREIGN KEY Constraints

    Corresponding columns in the foreign key and the referenced key must
    have similar internal data types inside InnoDB so that they can be
    compared without a type conversion. The size and sign of integer types
    must be the same. The length of string types need not be the same. For
    nonbinary (character) string columns, the character set and collation
    must be the same.

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

Sidebar

Related Questions

i got this error while trying to rebind a grid: ( Parent page (
Got this error message while trying to load view: The model item passed into
Got this error message while trying to configure an entitydatasource in the designer: My
I was trying to run a request factory example, but, I got this error
someone got this error before? what is the problem, i cannot figure out the
I am trying to drop a foreign key from a table referencing a specified
I m trying to add a foreign key to table table2 from table1 .
I’m trying to modify a table to make its primary key column AUTO_INCREMENT after
I'm trying to insert a String into a list. I got this error: TypeError:
Got this error on a big $_GET query in size ~9 000 symbols (they

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.