Starts in:
2 DAYS
9 HRS
55 MIN
0 SEC
Starts in:
2 D
9 H
55 M
0 S
Open Closed

Not going to use DB migration #202


User avatar
0
alexander.nikonov created

Hi,

we are not planning to use DB migration for our project tables - we have predefined DB tables structure, which will be changed by applying SQL scripts and the code just must be in-sync with it. At the same time, we understand DB migration mechanism is used in ABP Framework solution to create default tables (ABP[XXX], IDENTITYSERVER[XXX]) - so when ABP Framework gets updated, these tables might be updated accordingly.

Could you please suggest the best approach to use in the solution? Is it possible to go without DbMigration-related projects at all? Or it needs to be some selective migration? How to set it up?


5 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    You can keep migration project, use dotnet ef migrations script command to generates sql and apply to database(just remove __EFMigrationsHistory table changes,you should not have this table). see https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet#dotnet-ef-migrations-script

  • User Avatar
    0
    alexander.nikonov created

    I've tried that (I used EntityFrameworkCore project as a base and added the Microsoft.EntityFrameworkCore.Design reference as asked by the tool). After running migration tool, I'm getting

    Unable to create an object of type 'XXXXDbContext' //this is the class inherited from AbpDbContext<XXXXDbContext>

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Try:

    EntityFrameworkCore.DbMigrations instead of EntityFrameworkCore project. See https://docs.abp.io/en/abp/latest/Startup-Templates/Application#entityframeworkcore-dbmigrations-project

  • User Avatar
    0
    alexander.nikonov created

    I see now... But is dotnet-ef tool the same thing as Microsoft.EntityFrameworkCore.Tools package? So basically I can use PM commands add-migration / script-migration -from 0 and so on instead? I just need to leave only ABP-related tables inside CentralToolsMigrationsDbContext.OnModelCreating method.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Yes , there are the same.

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