[英].net core tables doesn't exist
我的問題是:我的項目具有授權和身份驗證。 我為這些添加了一些模型(文章、類別)、repos 和 irepos。 數據庫僅顯示身份框架創建的表。 有我自己的不足。 我已經完成遷移和更新數據庫。 以下屏幕來自 SQL SOE
啟動:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddControllersWithViews();
services.AddRazorPages();
services.AddTransient<IArticleRepository, ArticleRepository>();
services.AddTransient<ICategoryRepository, CategoryRepository>();
}
數據庫上下文:
using System;
using System.Collections.Generic;
using System.Text;
using Blog.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace Blog.Data
{
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public DbSet<Article> Articles;
public DbSet<Category> Categories;
public DbSet<IdentityUser> Users;
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Article>().HasData(new Article { Id=1, CategoryId=1, Content="cont", Title="title" });
}
}
}
我刪除了數據庫和所有遷移。 添加
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
遷移和更新后 - 有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.