C
C#2y ago
Alizer

how to add a table to an existing ef core database created using EnsureCreated()?

I have an existing SQLite database (30GB in size) which was created using EnsureCreated(), now I need to add a table which I tried using migrations (I passed dotnet ef database update) on the command line but it causes Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 1: 'table "AspNetRoles" already exists'. error, I did a lot of research and it seems like I needed to create the database via migrations. How do I add a table when the ef core database is created via EnsureCreated()? Do I have to create the db via migrations and fill it with data from the existing db? can there be a way in which I can add the table be it via code?
2 Replies
Alizer
Alizer2y ago
also there is no way I can just throw away the existing db, it already has many important data because i basically host a forums site
Angius
Angius2y ago
You add a table by creating a new model and adding a DbSet of that model to the DbContext Then you generate and apply migrations