# Duplicate field values to another field across collection?

**URL:** https://discourse.getcockpit.com/t/duplicate-field-values-to-another-field-across-collection/1452
**Category:** Support
**Created:** [May 11, 2020, 7:11pm UTC](https://discourse.getcockpit.com/t/duplicate-field-values-to-another-field-across-collection/1452 "2020-05-11T19:11:54Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jasonday](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@jasonday](https://discourse.getcockpit.com/u/jasonday)
#### Post date: [May 11, 2020, 7:11pm UTC](https://discourse.getcockpit.com/t/duplicate-field-values-to-another-field-across-collection/1452/1 "2020-05-11T19:11:54Z")

</div>

I have a text field that I would like to change the name of, but when I do so, the current value disappears. Is there a way to change the name of a field and keep it’s value? and/or can I create a new text field and copy the data from the first field into it?

---

<div class="post-metadata">

### Author: ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)
#### Post date: [May 12, 2020, 5:22pm UTC](https://discourse.getcockpit.com/t/duplicate-field-values-to-another-field-across-collection/1452/2 "2020-05-12T17:22:29Z")

</div>

You can use a cli command to rename a field.

```bash
cd /path/to/cockpit

# if not executable
# chmod +x ./cp

./cp collection/renamefield --collection collection_name --field old_field --newfield new_field

# if php PATH misconfigured
# php ./cp collection/renamefield --collection collection_name --field old_field --newfield new_field

```

See also:

> <https://github.com/agentejo/cockpit/blob/next/modules/Collections/cli/collection/renamefield.php>

---

<div class="post-metadata">

### Author: ![jasonday](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@jasonday](https://discourse.getcockpit.com/u/jasonday)
#### Post date: [May 13, 2020, 4:57pm UTC](https://discourse.getcockpit.com/t/duplicate-field-values-to-another-field-across-collection/1452/3 "2020-05-13T16:57:27Z")

</div>

> [@raffaelj](#):
>
> ./cp collection/renamefield --collection collection\_name --field old\_field --newfield new\_field

Unfortunately, this didn’t copy over the values in the old field to the new field

---

<div class="post-metadata">

### Author: ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)
#### Post date: [May 19, 2020, 4:26pm UTC](https://discourse.getcockpit.com/t/duplicate-field-values-to-another-field-across-collection/1452/4 "2020-05-19T16:26:20Z")

</div>

@jasonday Sorry for the late reply. I was a bit busy.

Now I tried to reproduce it with a test collection “renametest”.

- It had two fields “title” and “wrongname” with two entries.
- I navigated to `/path/to/cockpit`
- Because of a misconfiguration in my current Docker image, I had to prepend `php ` to the command.

Failed:

```auto
[user@host cockpit]$ cp collection/renamefield --collection renametest --field wrongname --newfield correctname
cp: unrecognized option '--collection'
Try 'cp --help' for more information.

```

Worked:

```auto
[user@host cockpit]$ php cp collection/renamefield --collection renametest --field wrongname --newfield correctname
Field <wrongname> renamed to <correctname>!

```

- Now the database was updated.
- I had to manually rename the field “wrongfield” to “correctfield” in my collection settings. Afterwards both old entries were moved.
