[英]Problem with publishing asp.net to Azure. Database error
I have a problem with the application when sharing it on azure.在 azure 上共享应用程序时,我遇到了问题。 It works fine locally, but when publishing it, the message appears:
它在本地运行良好,但是在发布时,会出现以下消息:
There is already an object named 'Categories' in the database.数据库中已经有一个名为“Categories”的 object。
Here is my Context.cs这是我的Context.cs
namespace Sklep_komputerowy.Models
{
public class ProductContext : DbContext
{
public ProductContext() : base("Sklep_komputerowy")
{
}
public DbSet<Category> Categories { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<CartItem> ShoppingCartItems { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<OrderDetail> OrderDetails { get; set; }
}
}
and category.cs和category.cs
namespace Sklep_komputerowy.Models
{
public class Category
{
[ScaffoldColumn(false)]
public int CategoryID { get; set; }
[Required, StringLength(100), Display(Name = "Nazwa")]
public string CategoryName { get; set; }
[Display(Name = "Opis")]
public string Description { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
}
The application was created on the basis of the wingtip toys tutorial:该应用程序是在翼尖玩具教程的基础上创建的:
https://docs.microsoft.com/pl-pl/aspnet/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/ https://docs.microsoft.com/pl-pl/aspnet/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/
I have the code-first option selected in the publication profile我在发布配置文件中选择了代码优先选项
I migrated database using commands我使用命令迁移了数据库
Enable-Migrations
Add-migration firstMigration
Update-Database
you have two option 1.delete Categories table on azure sever or 2. find the migration that creating categories table and remove it from migration file then deploy again你有两个选项 1.删除 azure 服务器上的类别表或 2.找到创建类别表的迁移并将其从迁移文件中删除然后再次部署
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.