Open Closed

How can I change database table prefix? #699


User avatar
0
alper created
Support Team Director

ABP creates database tables with prefix. For example some tables have Abp prefix like "AbpUsers", and some tables have App prefix like "AppBooks" and some tables have Blg like "BlgBlogs". How can I change database tables prefix?


1 Answer(s)
  • User Avatar
    0
    alper created
    Support Team Director

    Each module can define its database table prefix. For example Blog module sets its database table as Blg. This is done in the module. See BloggingDbProperties.cs . If you want to overwrite this prefix you can do it in your Domain Module class as below.

    Volo.Blogging.BloggingDbProperties.DbTablePrefix  = "Xyz"
    

    For Identity Server module you can set it as below

    Volo.Abp.IdentityServer.AbpIdentityServerDbProperties.DbTablePrefix = "Ids";
    

    This behavour is same for other modules as well.

    The essential framework modules have Abp prefix. Check out the documentation https://docs.abp.io/en/abp/latest/Entity-Framework-Core-Migrations#table-prefixes


    In your application, your table prefix is App by default. You can change this in the following file: Acme.BookStore\src\Acme.BookStore.Domain\BookStoreConsts.cs

    namespace Acme.BookStore
    {
        public static class BookStoreConsts
        {
            public const string DbTablePrefix = "Xyz"; //<----- this is the variable to set your table prefix
    
            public const string DbSchema = null;
        }
    }
    

    This change requires the re-creation of migrations. To do this; delete your existing migrations in the Migrations folder Acme.BookStore.EntityFrameworkCore.DbMigrations\Migrations\ and then add migrations using add-migration Initial

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09