- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个 ASP.NET MVC5 Web 应用程序。我正在使用 Entity Framework 6 来满足我的数据存储需求。我在启用迁移的情况下使用它的代码优先功能。自动迁移设置为 false。
我有两个表要更改。第一个表称为类(class),这是它的模型。
public class course
{
[Key]
public int courseID { get; set; }
public int categoryID { get; set; }
public int PaymentOptionsID { get; set; }
[Required]
[DisplayName("Course Code")]
public string courseCode { get; set; }
[Required]
[DisplayName("Course Name")]
public string courseName { get; set; }
[Required]
[DataType(DataType.Currency)]
public decimal price { get; set; }
[DataType(DataType.MultilineText)]
[DisplayName("Course Description")]
[StringLength(255, ErrorMessage = "Only a maximum of 255 characters are allowed")]
public string courseDescription { get; set; }
[Required]
[DisplayName("Study Material")]
public string courseIncludes { get; set; }
public string courseInfoUrl { get; set; }
public virtual ICollection<enrollment> enrollment { get; set; }
public virtual courseCategory courseCategory { get; set; }
public virtual PaymentOptions PaymentOptions { get; set; }
}
第二个表的名称是 paymentOptions,这是它的模型。
public class PaymentOptions
{
[Key]
public int PaymentOptionsID { get; set; }
public int courseID { get; set; }
[DisplayName("Payment Options")]
public string paymentOption {get; set; }
}
我添加了 5 个迁移,它们运行良好。现在我正在尝试添加第六个,我正在尝试对表进行以下更改
public class course
{
[Key]
public int courseID { get; set; }
public int categoryID { get; set; }
public int PaymentOptionsID { get; set; }
[Required]
[DisplayName("Course Code")]
public string courseCode { get; set; }
[Required]
[DisplayName("Course Name")]
public string courseName { get; set; }
[Required]
[DataType(DataType.Currency)]
public decimal price { get; set; }
[Required]
[DisplayName("Course Includes")]
public string courseIncludes { get; set; }
public string courseInfoUrl { get; set; }
public virtual ICollection<enrollment> enrollment { get; set; }
public virtual courseCategory courseCategory { get; set; }
public virtual ICollection<PaymentOptions> PaymentOptions { get; set; }
}
public class PaymentOptions
{
[Key]
public int PaymentOptionsID { get; set; }
public int courseID { get; set; }
[DisplayName("Payment Options")]
public string paymentOption {get; set; }
public virtual ICollection<course> course { get; set; }
}
当我添加迁移时它工作正常但是当我突然点击更新数据库命令时我得到这个错误
“找不到对象“dbo.course”,因为它不存在或您没有权限。”
这就是迁移的样子。
public partial class AddPaymentOptionsagain : DbMigration
{
public override void Up()
{
RenameTable(name: "dbo.course", newName: "PaymentOptionscourse");
DropForeignKey("dbo.course", "PaymentOptions_PaymentOptionsID", "dbo.PaymentOptions");
DropIndex("dbo.course", new[] { "PaymentOptions_PaymentOptionsID" });
AddColumn("dbo.course", "PaymentOptionsID", c => c.Int(nullable: false));
CreateIndex("dbo.PaymentOptionscourse", "PaymentOptions_PaymentOptionsID");
CreateIndex("dbo.PaymentOptionscourse", "course_courseID");
AddForeignKey("dbo.PaymentOptionscourse", "PaymentOptions_PaymentOptionsID", "dbo.PaymentOptions", "PaymentOptionsID", cascadeDelete: true);
AddForeignKey("dbo.PaymentOptionscourse", "course_courseID", "dbo.course", "courseID", cascadeDelete: true);
DropColumn("dbo.course", "courseDescription");
DropColumn("dbo.course", "PaymentOptions_PaymentOptionsID");
}
public override void Down()
{
AddColumn("dbo.course", "PaymentOptions_PaymentOptionsID", c => c.Int());
AddColumn("dbo.course", "courseDescription", c => c.String(maxLength: 255));
DropForeignKey("dbo.PaymentOptionscourse", "course_courseID", "dbo.course");
DropForeignKey("dbo.PaymentOptionscourse", "PaymentOptions_PaymentOptionsID", "dbo.PaymentOptions");
DropIndex("dbo.PaymentOptionscourse", new[] { "course_courseID" });
DropIndex("dbo.PaymentOptionscourse", new[] { "PaymentOptions_PaymentOptionsID" });
DropColumn("dbo.course", "PaymentOptionsID");
CreateIndex("dbo.course", "PaymentOptions_PaymentOptionsID");
AddForeignKey("dbo.course", "PaymentOptions_PaymentOptionsID", "dbo.PaymentOptions", "PaymentOptionsID");
RenameTable(name: "dbo.PaymentOptionscourse", newName: "course");
}
}
stackoverflow上的问题我都看了,http://forums.asp.net , msdn.microsoft.com › SQL Server 和我似乎仍然无法弄清楚为什么会发生这种情况以及我需要做些什么来修复它。
任何帮助将不胜感激。提前致谢
最佳答案
我在您的语句序列中看到了问题。您在重命名后试图引用该对象。
RenameTable(name: "dbo.course", newName: "PaymentOptionscourse");
DropForeignKey("dbo.course", "PaymentOptions_PaymentOptionsID", "dbo.PaymentOptions");
DropIndex("dbo.course", new[] { "PaymentOptions_PaymentOptionsID" });
试试这个
RenameTable(name: "dbo.course", newName: "PaymentOptionscourse");
DropForeignKey("dbo.PaymentOptionscourse", "PaymentOptions_PaymentOptionsID", "dbo.PaymentOptions");
DropIndex("dbo.PaymentOptionscourse", new[] { "PaymentOptions_PaymentOptionsID" });
AddColumn("dbo.PaymentOptionscourse", "PaymentOptionsID", c => c.Int(nullable: false));
CreateIndex("dbo.PaymentOptionscourse", "PaymentOptions_PaymentOptionsID");
CreateIndex("dbo.PaymentOptionscourse", "course_courseID");
AddForeignKey("dbo.PaymentOptionscourse", "PaymentOptions_PaymentOptionsID", "dbo.PaymentOptions", "PaymentOptionsID", cascadeDelete: true);
AddForeignKey("dbo.PaymentOptionscourse", "course_courseID", "dbo.PaymentOptionscourse", "courseID", cascadeDelete: true);
DropColumn("dbo.PaymentOptionscourse", "courseDescription");
DropColumn("dbo.PaymentOptionscourse", "PaymentOptions_PaymentOptionsID");
关于c# - 找不到对象 "dbo.course",因为它不存在或您没有权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29228790/
我正在使用 Gunicorn 为 Django 应用程序提供服务,它工作正常,直到我将其超时时间从 30 秒更改为 900000 秒,我不得不这样做,因为我有一个用例需要上传和处理一个巨大的文件(过程
我有一个带有非常基本的管道的Jenkinsfile,它可以旋转docker容器: pipeline { agent { dockerfile { args '-u root' } } stag
在学习 MEAN 堆栈的过程中,我遇到了一个问题。每当我尝试使用 Passport 验证方法时,它都不会返回任何响应。我总是收到“localhost没有发送任何数据。ERR_EMPTY_RESPONS
在当今的大多数企业堆栈中,数据库是我们存储所有秘密的地方。它是安全屋,是待命室,也是用于存储可能非常私密或极具价值的物品的集散地。对于依赖它的数据库管理员、程序员和DevOps团队来说,保护它免受所
是否可以创建像图片上那样的边框?只需使用 css 边框属性。最终结果将是没 Angular 盒子。我不想添加额外的 html 元素。我只想为每个 li 元素添加 css 边框信息。 假设这是一个 ul
我是一名优秀的程序员,十分优秀!