【问题标题】:ABP.IO How to change DbTablePrefix for all ModulesABP.IO 如何更改所有模块的 DbTablePrefix
【发布时间】:2021-02-14 10:34:14
【问题描述】:

抱歉,我无法在 Changing table prefix and schema of ABP.IO 上提问,所以我正在创建另一个问题。

在 ABP.IO 的文档中,它提到了更改表架构 (https://docs.abp.io/en/abp/latest/Entity-Framework-Core-Migrations),我还查看了 git 问题 (https://github.com/abpframework/abp/issues/1429),指的是添加了 AbpCommonDbProperties 以及关于将其添加到您的程序开始,但是我在所有项目中都尝试了几种不同的方法,但似乎无法使其正常工作。 git 注释表明这些更改应该适用于所有模块,并且查看了代码我可以看到设置应该如何使用它,但是设置模块必须有一些不同(或者我认为错误源于本地化模块)。

运行我的 HttpApi.Host 项目,我得到“Microsoft.Data.SqlClient.SqlException (0x80131904):无效的对象名称“设置”。我设法在迁移期间设置了默认前缀,因此我的表都删除了它们的前缀,但是我似乎无法让主机程序使用相同的前缀。

我的解决方案包含一个 HttpApi.Host 和 IdentityServer 项目。鉴于 ABP 的高级定制,我有点不知所措,为什么这不能更容易(或者在我的情况下,根本没有)。

【问题讨论】:

    标签: database schema customization abp


    【解决方案1】:

    我的测试步骤如下。

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

    2. 配置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. 删除DbTablePrefixTest.EntityFrameworkCore.DbMigrations项目下的Migrations文件夹。
    2. dotnet ef 迁移添加“初始”
    3. dotnet ef 数据库更新

    结果如下:

    【讨论】:

    • 我看到您使用的是分层的,那么当您运行 Identity Server 和 WebAppHost 时会发生什么?正如我所说,当我运行代码时出现错误。我已成功应用 DbMigrator 的迁移。
    • 参见#1387 (comment)。您可以根据search查看哪些模块使用了ABPCommonDBProperties。
    猜你喜欢
    • 1970-01-01
    • 2014-09-04
    • 1970-01-01
    • 2021-01-13
    • 2016-03-16
    • 2021-07-05
    • 1970-01-01
    • 2017-01-13
    • 2023-04-10
    相关资源
    最近更新 更多