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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:18:56+00:00 2026-05-17T20:18:56+00:00

I have just managed to migrate a pretty big database from SQL Server to

  • 0

I have just managed to migrate a pretty big database from SQL Server to MySQL. I didn’t set the primary keys to auto increment during the migration because the tables have relationships based on ids as primary keys which are foreign keys in another table.

Now for adding new records I want to alter the primary key ‘id’ columns in all tables to be autoincrement but starting from the last highest number in the id column in each table.

What’s the best way to do this without losing the relationships I already have?

UPDATE: Trying to add autoincrement gives me this error:

ERROR 1067: Invalid default value for 'id'

SQL Statement:

ALTER TABLE `skandium`.`brands` CHANGE COLUMN `id` `id` INT(11) NOT NULL DEFAULT '0' AUTO_INCREMENT

ERROR 1050: Table 'brands' already exists

SQL Statement:

CREATE TABLE `brands` (
  `id` int(11) NOT NULL DEFAULT '0',
  `brand` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
  • 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-17T20:18:56+00:00Added an answer on May 17, 2026 at 8:18 pm

    Just add the auto-increment on your needed columns. It won’t affect existing rows. It will start with the next available value.

    Note that a column being auto-increment means just that if you don’t assign a value to it one will be added by MySQL. If you want to supply explicit values you can do so without anything special happening. So you could have set those columns to auto-increment right from the start.

    A column with auto-increment cannot have an explicit default value.

    Tested

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

Sidebar

Related Questions

I have just set up cruise control.net on our build server, and I am
How do you manage your sql server database build/deploy/migrate for visual studio projects? We
I have just inherited a server application, however it seems that the only copy
I have just installed VMWare Server 2.0 on a fresh Fedora Core 8 install.
I have just managed to enable full-text searching to make searching for products in
So I have just managed to build a timer on my iOS app I'm
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have just started playing with ASP.NET MVC and have stumbled over the following situation.
I have just installed C# for the first time, and at first glance it

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.