Open Closed

New tenant not create admin user #10499


User avatar
0
laura created

create a new tenant don't create admin user


3 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    • In ABP, the tenant admin user is created by the data seeding process that runs right after the tenant is created. If the seeding/migration handler fails (often due to a connection string / UoW issue), the tenant record is created but the admin user is not.

    • Fix path (the known/common cause from ABP support case #2240):

      1. Find the handler in your solution that reacts to tenant creation (it’s typically named like:
        • YourProjectNameTenantDatabaseMigrationHandler or YourProjectNameTenantCreatedEventHandler
        • and it handles TenantCreatedEto)
      2. Inside its MigrateAndSeedForTenantAsync(...) (or similarly named) method, locate the seeding Unit Of Work block. If you see something like:
    using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: true))
         {
             await _dataSeeder.SeedAsync(
                 new DataSeedContext(tenantId)
                     .WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, adminEmail)
                     .WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, adminPassword)
             );
    
             await uow.CompleteAsync();
         }
    
     change it to **requiresNew: false**:
    
    using (var uow = _unitOfWorkManager.Begin(requiresNew: false, isTransactional: true))
         {
             await _dataSeeder.SeedAsync(
                 new DataSeedContext(tenantId)
                     .WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, adminEmail)
                     .WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, adminPassword)
             );
    
             await uow.CompleteAsync();
         }
    
    1. Re-create the tenant (or manually trigger seeding for that tenant) and verify AbpUsers contains an admin record with that tenant’s TenantId.
    • If you’re using separate database per tenant, also ensure the tenant’s Default connection string is set and reachable; otherwise the migration/seed step can time out and admin user won’t be created.

    Links:

    • https://abp.io/support/questions/2240
    • https://abp.io/docs/latest/kb/can-not-login-with-admin-user
    • https://abp.io/docs/latest/framework/infrastructure/data-seeding
    • https://abp.io/docs/latest/framework/architecture/multi-tenancy
    • https://abp.io/community/articles/51nvl4u9

    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    laura created

    The user sometimes was created sometimes no

  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    • This “sometimes created, sometimes not” behavior almost always means the tenant creation succeeded, but the follow-up migration/seed step intermittently fails (typically a timeout / connection resolution problem inside the tenant-created event handler). When that happens, ABP doesn’t roll back the tenant record, but the admin user seed doesn’t complete, so you observe randomness depending on timing/environment load.

    • Apply the fix in your tenant-created handler to remove the intermittent UoW/connection-string resolution problem:

    1. In your solution, locate the handler that runs after tenant creation (usually named like *TenantDatabaseMigrationHandler and handles TenantCreatedEto).
    2. In MigrateAndSeedForTenantAsync(...), find the seeding block and ensure it uses requiresNew: false:
    // Seed data
    using (var uow = _unitOfWorkManager.Begin(requiresNew: false, isTransactional: true))
    {
        await _dataSeeder.SeedAsync(
            new DataSeedContext(tenantId)
                .WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, adminEmail)
                .WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, adminPassword)
        );
    
        await uow.CompleteAsync();
    }
    

    This change prevents starting a new UoW that can intermittently fail to resolve the correct connection/tenant context (and then time out), which is what causes “sometimes yes, sometimes no”.

    • Also do these two operational checks (because they are the other common source of “random” failures):
      • Check your logs at the moment you create the tenant; if you see a database timeout/connection error during “migrate/seed”, that’s the reason the admin user wasn’t created.
      • If using separate DB per tenant, make sure the tenant’s Default connection string is valid/reachable (ABP will create DB + run migrations + seed; if any of these fails, admin user won’t be created).

    Notes:

    • If you already have tenants without admin users, you can re-run the seed/migration for that tenant (from the SaaS UI “Apply Database Migrations” if you use it, or by executing your migrator/seed pipeline for that tenant).

    Links (validated):

    • https://abp.io/support/questions/2240
    • https://abp.io/docs/latest/kb/can-not-login-with-admin-user
    • https://abp.io/docs/latest/framework/infrastructure/data-seeding
    • https://abp.io/docs/latest/framework/architecture/multi-tenancy
    • https://abp.io/community/articles/51nvl4u9

    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.3.0-preview. Updated on March 06, 2026, 09:11
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.