SQL ALTER TABLE ADD PRIMARY KEY error1064

For some reason, my sql script cannot add a primary key statement. I was wondering if anyone could explain why?

Here is the table instruction.

CREATE TABLE IF NOT EXISTS `wp_bwg_album` ( `id` bigint(20) NOT NULL, `name` varchar(255) NOT NULL, `slug` varchar(255) NOT NULL, `description` mediumtext NOT NULL, `preview_image` mediumtext NOT NULL, `random_preview_image` mediumtext NOT NULL, `order` bigint(20) NOT NULL, `author` bigint(20) NOT NULL, `published` tinyint(1) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 

And this is the trick in which he fails -

 ALTER TABLE `wp_bwg_album` ADD PRIMARY KEY (`id`); 

Linked to the table is the final statement.

 ALTER TABLE `wp_bwg_album` MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT; 

I got confused as a problem, SQL is a dump from my server. I am just updating my development server at home. using workbench MySql, I get standard error 1064.

16:58:40 ADD PRIMARY KEY ( id ) Error code: 1064. You have an error in your SQL syntax; check the manual that matches your MySQL server for the correct syntax to use next to 'ADD PRIMARY KEY ( id )' on line 1 0,000 s

Any help would be appreciated.

+5
source share
1 answer

Try the following:

 ALTER TABLE `wp_bwg_album` ADD CONSTRAINT `pk_wp_bwg_album` PRIMARY KEY (`id`); 

The name of the restriction can be any.

0
source

Source: https://habr.com/ru/post/1241053/


All Articles