C#C
C#9mo ago
AlisterKB

creating migrations on an existing DB to add a column(efcore)

so I have a webapi project, dotnet 8 efcore 8 and postgres
project was DB first and hence scaffolded. now I wanna add a property to an entity of mine AND/OR add a column to a table
I have always done db first and never done code first and have never touched migrations. tried adding migration but doing so it wants to create all tables with updated columns. tables already exist and have data I'd rather not lose (though it wouldn't be end of the world as it is a personal project for learning) so wondering how can I add a column without dropping my tables and not updating my table with sql command scaffolding it again. Most resources I've found involve somewhat hacky way of adding migration and deleting the content in up and down methods in migration though I don't understand how that might help ?
Was this page helpful?