You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kentico:修改页面类型字段名且保留现有值的方法

Fixing Kentico Field Rename Without Losing Data (Reserved Keyword Issue)

Got it, let's break this down and fix this properly—you're right about Function being a SQL reserved keyword, which is causing that syntax error. The reason your data went blank when renaming to BusinessFunction is because Kentico doesn't automatically migrate existing data when you just rename a field's code name directly in the admin. Here are a couple of solid solutions:

This is the safest approach to avoid data loss:

  1. Backup your database first—always do this before making schema changes!
  2. In the Kentico admin, go to your Staff page type and create a new field named BusinessFunction, matching the exact type, settings, and validation rules of the original Function field (e.g., text length, required status).
  3. Run a SQL script to copy data from the old field to the new one. Replace CMS_Staff with your actual Staff page type's database table name (it usually starts with CMS_ followed by the page type display name):
    UPDATE [CMS_Staff]
    SET [BusinessFunction] = [Function]
    -- We use square brackets around [Function] because it's a reserved SQL keyword
    
  4. Verify the migration worked: Open a few Staff pages in the admin and check that the BusinessFunction field has the same values as Function did.
  5. Once confirmed, delete the original Function field from the Staff page type.
  6. Update your repeater's WHERE condition to BusinessFunction LIKE '%insurance%'—no more syntax errors!

Option 2: Directly Rename the Database Column (More Technical)

If you'd prefer not to create a new field, you can sync the Kentico field definition with a database column rename:

  1. Backup your database—again, non-negotiable.
  2. In the Kentico admin, edit the Function field's settings: Change its Code name to BusinessFunction but don't save yet (or save, but note that the data will appear blank temporarily).
  3. Open your database management tool (like SSMS) and run this script to rename the actual database column:
    EXEC sp_rename 'CMS_Staff.Function', 'BusinessFunction', 'COLUMN';
    -- Syntax: sp_rename 'TableName.OldColumnName', 'NewColumnName', 'COLUMN'
    
  4. Go back to the Kentico admin, refresh the field settings page, and check your Staff pages—your data should now appear in the BusinessFunction field.
  5. Update your repeater's WHERE condition as needed.

Bonus: Quick Fix Without Renaming the Field

If you don't want to rename the field at all, you can just escape the reserved keyword in your WHERE condition by wrapping it in square brackets:

[Function] LIKE '%insurance%'

SQL will recognize [Function] as a column name instead of the reserved keyword, resolving the syntax error immediately. This is a great shortcut if renaming feels like overkill.


内容的提问来源于stack exchange,提问作者Michelle

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:32:39