Browse Source

fix(nocodb): populate column name to avoid duplicate field

pull/7022/head
աɨռɢӄաօռɢ 12 months ago
parent
commit
ac47dbf6fb
  1. 12
      packages/nocodb/src/services/tables.service.ts

12
packages/nocodb/src/services/tables.service.ts

@ -455,9 +455,21 @@ export class TablesService {
const mxColumnLength = Column.getMaxColumnNameLength(sqlClientType); const mxColumnLength = Column.getMaxColumnNameLength(sqlClientType);
const uniqueColumnNameCount = {};
for (const column of param.table.columns) { for (const column of param.table.columns) {
if (!isVirtualCol(column)) { if (!isVirtualCol(column)) {
column.column_name = sanitizeColumnName(column.column_name); column.column_name = sanitizeColumnName(column.column_name);
if (uniqueColumnNameCount[column.column_name]) {
let suffix = 1;
let targetColumnName = `${column.column_name}_${suffix++}`;
while (uniqueColumnNameCount[targetColumnName]) {
targetColumnName = `${column.column_name}_${suffix++}`;
}
column.column_name = targetColumnName;
}
uniqueColumnNameCount[column.column_name] = 1;
} }
if (column.column_name.length > mxColumnLength) { if (column.column_name.length > mxColumnLength) {

Loading…
Cancel
Save