c# - How to auto generate the MigrationBuilder from an existent DB -


i'm creating asp.net core project. project came file migration. file generate db. have tables in db , create migration file in sample.

sample:

migrationbuilder.createtable(                name: "aspnetroles",                columns: table => new                {                 id = table.column<string>(nullable: false),                 concurrencystamp = table.column<string>(nullable: true),                 name = table.column<string>(maxlength: 256, nullable: true),                 normalizedname = table.column<string>(maxlength: 256, nullable: true)               },               constraints: table =>               {                     table.primarykey("pk_aspnetroles", x => x.id);               }); 

if have existent table. how can create file?

first need decide on approach wanted go dbfirst or codefirst. files can generated automatically , can make changes file manually.

i recommend using codefirst because provides max control on models , dbcontext.

step1 : create codefirst model using existing database. codefirst model using existing database

step 2: type enable-migrations in package manager console

step 3: use (db)context , model generated database table. make changes model

step 4: type add-migration [some name identify migration] in package manager console

step 5: check generated migration file.

step 6: type update-database in package manager console

now changes updated database. on can codefirst approach handle changes database.

hope helps!


Comments

Popular posts from this blog

php - isset function not working properly -

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -