Change Form Code Name

Mirado Francky Randria asked on May 20, 2019 10:55

Hello every one,

I'm in Kentico 12 MVC, I need to change a Form's Code name in Database but I don't know how exactly to do it. Which table should I check?

Thanks for your answers

Correct Answer

Dmitry Bastron answered on May 20, 2019 11:36

Hi Mirado,

By default Kentico doesn't allow to change Form Code Name and Table Name. I would emphasize that it is not a good practice to amend the objects in database directly. Maybe you will be ok with just changing Display Name instead, please consider this option. Or create a new Form object instead with a proper name (this would be the best option).

But if you're sure in what are you doing these are the tasks (as per my knowledge, there might be more). As an example I will be using "Contact Us" form from Dancing Goat MVC test site:

  1. Perform a database backup
  2. Rename the Form_DancingGoatMvc_ContactUsNew database table
  3. Amend the CMS_Form record (change FormName) of Contact Us form
  4. Check and amend the CMS_Class record (check and change ClassName, ClassXmlSchema, ClassFormDefinition, ClassTableName if needed)
  5. Restart the website, regenerate the form code in Forms application (if you are using it) and update the form generated code in your solution

If you also want to change ID column name please check all the columns in CMS_Class table, there might be more references to ID column name.

2 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on May 20, 2019 15:36

The best option we've come across, assuming its not a page type with data tied to it, is to export the object and download the files. From there unzip the files and modify the objects in the files accordingly. You'll find most of your modifications will be in the Objects directory. There should be a definition file which will have all the areas you need to update. A simply find and replace of the old code name and replace it with the new code name should get you about half way done. Then you'll need to find and replace the old database table name with the new database table name.

After you've made your modifications to the files, zip them back up in the same structure as you unzipped them from. Upload them to Kentico under Sites > Import sites and objects. You'll be importing a new version of your form with all the proper names and tables updated AND it eliminates the need to touch the database tables.

1 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on May 20, 2019 15:47

Brendan,

I've got a small concern about this approach. If you would go export-import route, you will have a form object with the same GUID but different db name. I'm not sure if Kentico then rename the existing object in the database. I have a feeling it will create a new table but not rename the existing one (which is almost the same as creating a new Form). Or import will even fail with key mismatch error. Have you tried this with Forms yourself and can you confirm the behavior?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on May 20, 2019 17:01

Dmitry,

We've done this approach for 10 years without issue. It's a safer approach than touching the database, especially if page type data isn't included. On import, it checks the code name and if it doesn't exist, it creates a new one so no worries about the GUID being a duplicate.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.