✅ Updating Migrations

From my understanding Migrations are the code for EF to create a SQL DB. Ive followed this crash course https://www.youtube.com/watch?v=BfEjDD8mWYg&t=2848s to create my first one but I added more properties to the model so wondering how to update the migration to include those properties on the table. Any help would uh help haha. Does anyone have any tutorials or info on migrations and how to work with them?
freeCodeCamp.org
YouTube
ASP.NET Core Crash Course - C# App in One Hour
Learn how to create a web database app in ASP.NET Core using Visual Studio and the C# language. This tutorial will show you how to : - Use the MVC (Model View Controller) design pattern. - Configure database tables using the Entity framework. - Setup of classes as models. Customize Razor forms. - Create methods inside a controller. - Style an A...
10 Replies
Anu6is
Anu6is12mo ago
just like you added the initial migration, you do the same for every new migration
EricAwesomeness
EricAwesomenessOP12mo ago
So do i delete the initial migration then? Also whats the naming convention for the others does it matter?
Anu6is
Anu6is12mo ago
no, don't delete it, they are compounded to give the final state naming doesn't matter, just make it unique
mg
mg12mo ago
Your understanding isn't quite correct Migrations are how EF makes changes to the database to make it reflect your DbContext The initial migration will indeed be creating everything, but that's just the initial one A migration could also do something like change the type of a column or create or drop a table
EricAwesomeness
EricAwesomenessOP12mo ago
Ah okay so as I make changes to my DbContext do i just create a new migration and end up with like 40 of them in the folder lol? Well I wouldnt make changes to the DbContext just to the Models rights?
mg
mg12mo ago
That's one option. You can also re-create the first migration every time, which is what I do until I need to start caring about the data in the database Yeah, when I say context I mean the DbContext itself and any model that's stored in your database
EricAwesomeness
EricAwesomenessOP12mo ago
That seems like what I would like to do more at least until I stop changing it as much. Whats the command for that or is there a place I can find it?
mg
mg12mo ago
dotnet ef database update 0 to revert the database, dotnet ef migrations remove to remove the migration, and then dotnet ef migrations add InitialCreate to create it again And dotnet ef database update after you've created the new one
EricAwesomeness
EricAwesomenessOP12mo ago
Sweet thanks a ton mg I appreciate the help king
mg
mg12mo ago
ofc I just ended up batching it all up into a script Then you can do a dotnet build beforehand and pass --no-build to all the EF calls so it doesn't rebuild your project every time
Want results from more Discord servers?
Add your server