Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11691

Why database update is not adding the table in SQL Server?

$
0
0

I am trying to add a model (table) to a SQL Server database, but I am getting an error.

Here is what I tried - in program.cs:

builder.Services.AddDbContext<DataContext>(options =>        options.UseSqlServer(builder.Configuration.GetConnectionString("Default")));

In appsettings.json I have:

"ConnectionStrings": {"Default": "Server=RWAHDAN;Database=HSPA2024;Integrated Security=False;User Id=sa; Password=mypassword;"},

And this is my City model class:

public class City{    public int Id { get; set; }    public string Name { get; set; }}

Lastly I have my datacontext:

public class DataContext : DbContext{    public DataContext(DbContextOptions<DataContext> options): base(options) {}    public DbSet<City> Cities { get; set; }}

Migration is ok but updating database is not.

enter image description here


Viewing all articles
Browse latest Browse all 11691

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>