Base solution for your next web application
Open Closed

Disable automatic migration in web host #12622


User avatar
0
gerryp created

I am just upgrading to v15.0.0. I would like to know how to disable automatic database migration in the web host. Thanks.

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

2 Answer(s)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @gerryp

    On the ASP.NET Zero side, the Web.Host project does not run automatic database migrations by default. In other words, when the application starts, there is no Migrate() call or similar migration trigger mechanism executed automatically.

    Within Web.Host, only the seeding process is controlled. This is managed by the SkipDbSeed flag inside AbpZeroTemplateEntityFrameworkCoreModule. If SkipDbSeed = false, it only seeds data on top of the existing schema. This does not mean that migrations are executed.

    Database migration and initial setup operations are performed in two ways:

    Migrator Console Application Migrations + seeding are executed together through the MyCompanyName.AbpZeroTemplate.Migrator project. This is the recommended approach for production environments.

    Install Endpoint The installer mechanism used during first time setup triggers the migration process.

    Therefore, there is normally no need to disable automatic migration on the Web.Host side, because migrations are not executed there in the first place. If the goal is to disable the seeding process, setting SkipDbSeed = true is sufficient.

    You can also add the following technical recommendation at the end of your response:

    If you want to completely disable seeding on the Web.Host side, you can set the SkipDbSeed flag inside the AbpZeroTemplateWebHostModule constructor:

    public AbpZeroTemplateWebHostModule(
        IWebHostEnvironment env,
        AbpZeroTemplateEntityFrameworkCoreModule abpZeroTemplateEntityFrameworkCoreModule)
    {
        _env = env;
        _appConfiguration = env.GetAppConfiguration();
    
        // Disable automatic seeding on Web.Host startup
        abpZeroTemplateEntityFrameworkCoreModule.SkipDbSeed = true;
    }
    

    This approach:

    Prevents seed execution during Web.Host startup

    Does not affect migration behavior (since Web.Host does not run migrations anyway)

    If you have any questions, please do not hesitate to contact us.

    If this explanation does not fully address your issue, feel free to share the situation with examples or provide a bit more detail. This will allow us to give you a clearer, more specific, and tailored response.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    gerryp created

    This was very helpful and thorough. Thanks you

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)