# Adding primary key with pt-online-schema-change fails

**URL:** <https://forums.percona.com/t/adding-primary-key-with-pt-online-schema-change-fails/14096>\
**Category:** Percona XtraDB Cluster 8.x\
**Created:** [January 25, 2022, 11:40am UTC](https://forums.percona.com/t/adding-primary-key-with-pt-online-schema-change-fails/14096 "2022-01-25T11:40:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![danarashad](https://avatars.discourse-cdn.com/v4/letter/d/7ab992/32.png) [@danarashad](https://forums.percona.com/u/danarashad)\
**Post date:** [January 25, 2022, 11:40am UTC](https://forums.percona.com/t/adding-primary-key-with-pt-online-schema-change-fails/14096/1 "2022-01-25T11:40:22Z")

</div>

I am using the following command to add a primary key to a table that does not have one.

```auto
 pt-online-schema-change --execute --alter 'ADD Primary Key (image_id)' D=datastore,t=images --no-drop-old-table --port 3306 --user root --host 127.0.0.1 --password xxx --alter-foreign-keys-method auto --no-version-check 

```

The error I am getting is

```auto
No slaves found. See --recursion-method if host db400 has slaves.
Not checking slave lag because no slaves were found and --check-slave-lag was not specified.
Operation, tries, wait:
analyze_table, 10, 1
copy_rows, 10, 0.25
create_triggers, 10, 1
drop_triggers, 10, 1
swap_tables, 10, 1
update_foreign_keys, 10, 1
No foreign keys reference `datastore`.`images`; ignoring --alter-foreign-keys-method.
Altering `datastore`.`images`...
You are trying to add an unique key. This can result in data loss if the data is not unique.
Please read the documentation for the --check-unique-key-change parameter.
You can check if the column(s) contain duplicate content by running this/these query/queries:
SELECT IF(COUNT(DISTINCT image_id) = COUNT(*),
       'Yes, the desired unique index currently contains only unique values',
       'No, the desired unique index contains duplicated values. There will be data loss'
) AS IsThereUniqueness FROM `datastore`.`images`;
Keep in mind that these queries could take a long time and consume a lot of resources
`datastore`.`images` was not altered.

```

The values in the table all unique but the table is not altered.

---

<div class="post-metadata">

**Author:** ![danarashad](https://avatars.discourse-cdn.com/v4/letter/d/7ab992/32.png) [@danarashad](https://forums.percona.com/u/danarashad)\
**Post date:** [January 25, 2022, 12:09pm UTC](https://forums.percona.com/t/adding-primary-key-with-pt-online-schema-change-fails/14096/2 "2022-01-25T12:09:45Z")

</div>

I had to add `--no-check-unique-key-change` after I made sure there was no duplicates.
