简体   繁体   English

将 asp.net 发布到 Azure 时出现问题。 数据库错误

[英]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.cscategory.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.

相关问题 使用 Code First 数据库将 ASP.NET 项目发布到 Azure 时遇到问题 - 权限 - Trouble publishing ASP.NET project with Code First database to Azure - Permission 使用Visual Studio 2012将具有数据库的ASP.net Web应用程序发布到Azure - Publishing ASP.net web application with database to Azure using Visual Studio 2012 发布到天蓝色后有关MVC4 asp.net登录应用程序的错误 - Error about a MVC4 asp.net login app after publishing to azure 将本地asp.net MVC应用程序发布到Azure时出现登录错误 - Getting login error while publishing local asp.net MVC application to azure 将带有类库的ASP.Net Core Web App发布到Azure时在主页上出现500错误 - Getting 500 Error on Home page when publishing ASP.Net Core Web App with class library to Azure 将Asp.Net Mvc,Web Api应用程序发布到Windows Azure - Publishing an Asp.Net Mvc,Web Api Application to Windows Azure ASP.NET MVC:连接到数据库的问题 - ASP.NET MVC: problem connecting to a database 连接到数据库ASP.NET时出现问题 - Problem while connecting to DataBase ASP.NET ASP.NET Core 1.1 在本地运行良好,但在发布到 Azure 时显示“启动应用程序时出错”。 - ASP.NET Core 1.1 runs fine locally but when publishing to Azure says “An error occurred while starting the application.” 发布后出错:字符串未被识别为有效的日期时间 asp.net - Error after publishing : String was not recognized as a valid DateTime asp.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM