ABP.IO How to change DbTablePrefix for all Modules

0

Sorry, I can't ask a question on Changing table prefix and schema of ABP.IO so I am creating another.

In the documentation for ABP.IO it mentions changing table schemas (https://docs.abp.io/en/abp/latest/Entity-Framework-Core-Migrations), I've also looked at the git issue (https://github.com/abpframework/abp/issues/1429) referring to the addition of the AbpCommonDbProperties and the comment about adding it to the beginning of your program however I have tried several different things in all my projects and cannot seem to get it to work. The git comment indicates that these changes should work for all modules and having looked at the code I can see how the settings should be using it, but there must be something different about the Settings Module (or I think the error originates in the Localization module).

Running my HttpApi.Host project I get 'Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid object name 'Settings'. I managed to set the default prefix during migration so my tables have all had their prefix removed, however I can't seem to get the host program to use the same prefix.

My solution contains a HttpApi.Host and IdentityServer project. Given the high-level of customisation that ABP has I'm a bit at a loss as to why this doesn't work easier (or in my case, at all).

database
schema
customization
abp
asked on Stack Overflow Feb 14, 2021 by Brett Morris

1 Answer

0

The steps for my test are as follows.

  1. abp new "DbTablePrefixTest" -t app -u mvc --tiered -d ef -csf true

  2. Configure DefaultModelBuilderConfigurationOptions

protected override void OnModelCreating(ModelBuilder builder)
{
    base.OnModelCreating(builder);

    /* Include modules to your migration db context */

    builder.ConfigurePermissionManagement(opt=>opt.TablePrefix=DbTablePrefixTestConsts.DbTablePrefix);
    builder.ConfigureSettingManagement(opt => opt.TablePrefix = DbTablePrefixTestConsts.DbTablePrefix);
    builder.ConfigureBackgroundJobs(opt => opt.TablePrefix = DbTablePrefixTestConsts.DbTablePrefix);
    builder.ConfigureAuditLogging(opt => opt.TablePrefix = DbTablePrefixTestConsts.DbTablePrefix);
    builder.ConfigureIdentity(opt => opt.TablePrefix = DbTablePrefixTestConsts.DbTablePrefix);
    builder.ConfigureIdentityServer(opt => opt.TablePrefix = DbTablePrefixTestConsts.DbTablePrefix);
    builder.ConfigureFeatureManagement(opt => opt.TablePrefix = DbTablePrefixTestConsts.DbTablePrefix);
    builder.ConfigureTenantManagement(opt => opt.TablePrefix = DbTablePrefixTestConsts.DbTablePrefix);

    /* Configure your own tables/entities inside the ConfigureDbTablePrefixTest method */

    builder.ConfigureDbTablePrefixTest();
}
  1. Delete Migrations folder under DbTablePrefixTest.EntityFrameworkCore.DbMigrations project.
  2. dotnet ef migrations add "Inital"
  3. dotnet ef database update

results are as follows:

answered on Stack Overflow Mar 1, 2021 by 向洪林

User contributions licensed under CC BY-SA 3.0