diff --git a/packages/twenty-server/src/database/commands/upgrade-version/0-30/0-30-migrate-email-fields-to-emails.command.ts b/packages/twenty-server/src/database/commands/upgrade-version/0-30/0-30-migrate-email-fields-to-emails.command.ts index 87ff3e5b0..2e4969297 100644 --- a/packages/twenty-server/src/database/commands/upgrade-version/0-30/0-30-migrate-email-fields-to-emails.command.ts +++ b/packages/twenty-server/src/database/commands/upgrade-version/0-30/0-30-migrate-email-fields-to-emails.command.ts @@ -305,14 +305,6 @@ export class MigrateEmailFieldsToEmailsCommand extends ActiveWorkspacesCommandRu ) { this.logger.log(`Migrating person email field of type EMAIL to EMAILS`); - await this.migrateDataWithinTable({ - sourceColumnName: 'email', - targetColumnName: 'emailsPrimaryEmail', - tableName: 'person', - workspaceQueryRunner, - dataSourceMetadata, - }); - const personEmailFieldMetadata = await this.fieldMetadataRepository.findOne( { where: { @@ -322,6 +314,22 @@ export class MigrateEmailFieldsToEmailsCommand extends ActiveWorkspacesCommandRu }, ); + if (!personEmailFieldMetadata) { + this.logger.log( + `Could not find person email field with standardId ${PERSON_STANDARD_FIELD_IDS.email}, skipping migration`, + ); + + return; + } + + await this.migrateDataWithinTable({ + sourceColumnName: 'email', + targetColumnName: 'emailsPrimaryEmail', + tableName: 'person', + workspaceQueryRunner, + dataSourceMetadata, + }); + if (personEmailFieldMetadata) { await this.fieldMetadataService.deleteOneField( {