{"record":{"id":"7e25b14c2c02b1cf","repo":"nopSolutions/nopCommerce","slug":"default-email-account-cannot-be-loaded","errorCode":null,"errorMessage":"Default email account cannot be loaded","messagePattern":"Default email account cannot be loaded","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"src/Libraries/Nop.Data/Migrations/UpgradeTo470/DataMigration.cs","lineNumber":157,"sourceCode":"\n                _dataProvider.UpdateEntitiesAsync(values);\n\n                pageIndex++;\n            }\n        }\n\n        // new permission\n        if (_dataProvider.GetTable<PermissionRecord>().Any(pr => string.Compare(pr.SystemName, \"AccessProfiling\", StringComparison.InvariantCultureIgnoreCase) == 0)) \n            _dataProvider.BulkDeleteEntitiesAsync<PermissionRecord>(pr => pr.SystemName == \"AccessProfiling\");\n\n        //#6890\n        //remove column\n        this.DeleteColumnsIfExists<Product>([\"IsTelecommunicationsOrBroadcastingOrElectronicServices\"]);\n\n        //New message template\n        if (!_dataProvider.GetTable<MessageTemplate>().Any(st => string.Compare(st.Name, MessageTemplateSystemNames.DELETE_CUSTOMER_REQUEST_STORE_OWNER_NOTIFICATION, StringComparison.InvariantCultureIgnoreCase) == 0))\n        {\n            var eaGeneral = _dataProvider.GetTable<EmailAccount>().FirstOrDefault() ?? throw new Exception(\"Default email account cannot be loaded\");\n            _dataProvider.InsertEntity(new MessageTemplate()\n            {\n                Name = MessageTemplateSystemNames.DELETE_CUSTOMER_REQUEST_STORE_OWNER_NOTIFICATION,\n                Subject = \"%Store.Name%. New request to delete customer (GDPR)\",\n                Body = $\"%Customer.Email% has requested account deletion. You can consider this in the admin area.\",\n                IsActive = true,\n                EmailAccountId = eaGeneral.Id\n            });\n        }\n\n        //#7031\n        var emailAccountTableName = nameof(EmailAccount);\n        var credentialsColumnName = \"UseDefaultCredentials\";\n\n        if (Schema.Table(emailAccountTableName).Column(credentialsColumnName).Exists())\n        {\n            var emailAccounts = _dataProvider.GetTable<EmailAccount>().ToList();\n            foreach (var item in emailAccounts)","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Data/Migrations/UpgradeTo470/DataMigration.cs#L139-L175","documentation":"In the UpgradeTo470 migration, when seeding the GDPR 'delete customer request' message template, the code loads the first EmailAccount via _dataProvider.GetTable<EmailAccount>().FirstOrDefault() and throws a bare Exception if none exists. The migration assumes at least one email account is present; an empty EmailAccount table aborts the upgrade.","triggerScenarios":"Running the 4.70 data migration on a database whose EmailAccount table is empty, so FirstOrDefault() returns null and the null-coalescing throw fires.","commonSituations":"Upgrading a database where email accounts were never configured or were all deleted; a partially restored dev database missing seed email accounts; test/staging DB seeded without the default email account.","solutions":["Before upgrading, ensure at least one EmailAccount row exists (create the default email account in admin or insert a seed row).","Restore/insert the default email account from a known-good backup before running the migration.","If the table is genuinely empty, add a temporary email account, complete the migration, then adjust as needed."],"exampleFix":"// before\nvar eaGeneral = _dataProvider.GetTable<EmailAccount>().FirstOrDefault() ?? throw new Exception(\"Default email account cannot be loaded\");\n\n// after (pre-migration fix: ensure a row exists)\nINSERT INTO EmailAccount (Email, DisplayName, Host, Port, Username, Password, EnableSsl, UseDefaultCredentials, SmtpFields, IsDefaultEmailAccount)\nVALUES ('store@example.com','Store','smtp.example.com',25,'user','pwd',1,0,'',1);","handlingStrategy":"validation","validationCode":"// Before running the 4.70 migration, confirm an email account exists\nif (!_dataProvider.GetTable<EmailAccount>().Any())\n    throw new InvalidOperationException(\"Create at least one EmailAccount before upgrading to 4.70.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure at least one EmailAccount row exists before any version upgrade.","Seed/restore the default email account in dev and staging DBs.","Include an email-account check in your pre-upgrade verification checklist."],"tags":["migration","database","email-account","upgrade","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}