{"record":{"id":"05cd73ee3f2142ac","repo":"nopSolutions/nopCommerce","slug":"default-email-account-cannot-be-loaded-05cd73","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/UpgradeTo480/DataMigration.cs","lineNumber":24,"sourceCode":"[NopUpdateMigration(\"2023-10-30 12:00:00\", \"4.80\", UpdateMigrationType.Data)]\npublic class DataMigration : Migration\n{\n    private readonly INopDataProvider _dataProvider;\n\n    public DataMigration(INopDataProvider dataProvider)\n    {\n        _dataProvider = dataProvider;\n    }\n\n    /// <summary>\n    /// Collect the UP migration expressions\n    /// </summary>\n    public override void Up()\n    {\n        //#7108 New message template\n        if (!_dataProvider.GetTable<MessageTemplate>().Any(st => string.Compare(st.Name, MessageTemplateSystemNames.ORDER_CANCELLED_VENDOR_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.ORDER_CANCELLED_VENDOR_NOTIFICATION,\n                Subject = \"%Store.Name%. Order #%Order.OrderNumber% cancelled\",\n                Body = $\"<p>{Environment.NewLine}<a href=\\\"%Store.URL%\\\">%Store.Name%</a>{Environment.NewLine}<br />{Environment.NewLine}<br />{Environment.NewLine}Order #%Order.OrderNumber% has been cancelled.{Environment.NewLine}<br />{Environment.NewLine}Customer: %Order.CustomerFullName%,{Environment.NewLine}<br />{Environment.NewLine}<br />{Environment.NewLine}<br />{Environment.NewLine}Order Number: %Order.OrderNumber%{Environment.NewLine}<br />{Environment.NewLine}Date Ordered: %Order.CreatedOn%{Environment.NewLine}<br />{Environment.NewLine}<br />{Environment.NewLine}%Order.Product(s)%{Environment.NewLine}</p>{Environment.NewLine}\",\n                IsActive = true,\n                EmailAccountId = eaGeneral.Id\n            });\n        }\n\n        //#5898\n        if (!_dataProvider.GetTable<MessageTemplate>().Any(st => string.Compare(st.Name, MessageTemplateSystemNames.QUANTITY_BELOW_VENDOR_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.QUANTITY_BELOW_VENDOR_NOTIFICATION,\n                Subject = \"%Store.Name%. Quantity below notification. %Product.Name%\\\"\",","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Data/Migrations/UpgradeTo480/DataMigration.cs#L6-L42","documentation":"In the UpgradeTo480 migration, when seeding the 'Order cancelled vendor notification' message template, the code does GetTable<EmailAccount>().FirstOrDefault() and throws a bare Exception if no email account exists. Blocks the 4.80 upgrade.","triggerScenarios":"Running the 4.80 migration on a DB with an empty EmailAccount table; FirstOrDefault() returns null and the ?? throw triggers.","commonSituations":"Upgrading a DB where email accounts were never set up or were deleted; dev/staging DB restored without seed email accounts.","solutions":["Ensure at least one EmailAccount row exists before running the 4.80 migration.","Insert/restore the default email account from a backup.","Create a temporary email account to satisfy the migration, then reconfigure."],"exampleFix":"// before\nvar eaGeneral = _dataProvider.GetTable<EmailAccount>().FirstOrDefault() ?? throw new Exception(\"Default email account cannot be loaded\");\n\n// after (pre-upgrade: seed an account)\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.80 migration, confirm an email account exists\nif (!_dataProvider.GetTable<EmailAccount>().Any())\n    throw new InvalidOperationException(\"Create at least one EmailAccount before upgrading to 4.80.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure at least one EmailAccount row exists before upgrading to 4.80.","Seed the default email account in dev/staging DBs.","Run a pre-upgrade data-integrity check for required reference rows."],"tags":["migration","database","email-account","upgrade","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}