Duplicate field values to another field across collection?

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?

You can use a cli command to rename a field.

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:

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

@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:

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

Worked:

[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.
1 Like