Can't add unique primary key

Hi.

I had a database working fine but I wanted to reset the primary key customer_id so the ID numbers would start at 1 again.

So I dropped the column and then added it again which worked ok.

Now, I'm trying to make it the Primary key, not null, unique and auto increment but I get the following error:

ERROR 1138: Invalid use of NULL value

SQL Statement:

ALTER TABLE `customer_database`.`customers`

CHANGE COLUMN `customer_id` `customer_id` VARCHAR(45) NOT NULL ,

ADD PRIMARY KEY (`customer_id`),

ADD UNIQUE INDEX `customer_id_UNIQUE` (`customer_id` ASC)



ERROR: Error when running failback script. Details follow.



ERROR 1050: Table 'customers' already exists

SQL Statement:

CREATE TABLE `customers` (

  `first_name` varchar(45) NOT NULL,

  `last_name` varchar(45) NOT NULL,

  `email_address` varchar(45) NOT NULL,

  `company_name` varchar(45) NOT NULL,

  `company_address` varchar(45) DEFAULT NULL,

  `job_path` varchar(100) NOT NULL,

  `username` varchar(45) NOT NULL,

  `password` varchar(45) NOT NULL,

  `alert_flag` varchar(45) NOT NULL,

  `notes` varchar(45) DEFAULT NULL,

  `customer_id` varchar(45) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=latin1
LVL 1
LetterpartAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Cornelia YoderArtistCommented:
CREATE TABLE `customers` (

  `first_name` varchar(45) NOT NULL,

  `last_name` varchar(45) NOT NULL,

  `email_address` varchar(45) NOT NULL,

  `company_name` varchar(45) NOT NULL,

  `company_address` varchar(45) DEFAULT NULL,

  `job_path` varchar(100) NOT NULL,

  `username` varchar(45) NOT NULL,

  `password` varchar(45) NOT NULL,

  `alert_flag` varchar(45) NOT NULL,

  `notes` varchar(45) DEFAULT NULL,

  `customer_id` int(11)  NOT NULL AUTO_INCREMENT,

   INDEX primaryIndex(`customer_id`),
   PRIMARY KEY(`customer_id`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LetterpartAuthor Commented:
Thanks, that did the trick.
0
Cornelia YoderArtistCommented:
You're welcome, glad to help :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.