如何解决无法在ASP.NET Core中更新数据库
我已经使用USERGOLD
和Add-Migration
创建了一个名为update-database
的表,并且工作正常,该表是在SQL Server中创建的,但是现在我要创建另一个表{{1 }}。
我创建了一个模型类,并且使用FoodMenu
和dbset
并在迁移中创建了表,但是当我运行add-migration
在SQL Server中创建表时,它不起作用。我收到错误消息
数据库中已经有一个名为“ UserGold”的对象
我不知道为什么update-database
进行以前的迁移。
Contexto:
update-database
我的迁移:
public class RestoContext : IdentityDbContext<RestoUser>
{
public RestoContext(DbContextOptions<RestoContext> options)
: base(options)
{
}
public DbSet<Menu> Menu { get; set; }
// public DbSet<Employees> Employee { get; set; }
public DbSet<Employees> Emp { get; set; }
public DbSet<Manager> Manager { get; set; }
public DbSet<GoldMenu> GoldMenu { get; set; }
public DbSet<UserGold> UserGold { get; set; }
public DbSet<FoodMenu> FoodMenu { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example,you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
}
}
控制台应用程序:
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Resto.Migrations
{
public partial class AddusergoldToDb : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "UserGold",columns: table => new
{
userId = table.Column<string>(nullable: false),Usermail = table.Column<string>(nullable: true),CardNumber = table.Column<string>(nullable: true),Validedate = table.Column<DateTime>(nullable: false),Amount = table.Column<float>(nullable: false)
},constraints: table =>
{
table.PrimaryKey("PK_UserGold",x => x.userId);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "UserGold");
}
}
}
数据库中已经有一个名为“ UserGold”的对象
解决方法
迁移过程似乎有问题,请在“ Package Manager控制台”中运行add-migration命令。
您的问题可能是重复的here
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。