2015-10-07 42 views
1

我增加了一些特性到ApplicationUser遷移,現在我想刪除這些屬性,但我有這樣的:表「XXX.dbo.aspnetusers」不存在,VS-mysql的

MySql.Data.MySqlClient.MySqlException (0x80004005):表'intranetproto.dbo.aspnetusers'不存在。

這是我想刪除屬性:

public class ApplicationUser : IdentityUser 
{ 
    public string Email { get; set; } 
    [Required] 
    public string FirstName { get; set; } 
    [Required] 
    public string LastName { get; set; } 
    public int SignatureId { get; set; } 

    public virtual Signature Signature { get; set; } 
    public virtual string FullName 
    { 

     get 
     { 
      return FirstName + " " + LastName; 
     } 

    } 

} 

這是我的身份模型(不含某些屬性)

public class ApplicationUser : IdentityUser 
{ 
    public string Email { get; set; } 


} 

[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))] 
public class ApplicationDbContext : IdentityDbContext<ApplicationUser> 
{ 
    public ApplicationDbContext() 
     : base("DefaultConnection") 
    { 
    } 

    public System.Data.Entity.DbSet<LocalIdentity.Models.Model> Models { get; set; } 

    public System.Data.Entity.DbSet<LocalIdentity.Models.Quote> Quotes { get; set; } 

    public System.Data.Entity.DbSet<LocalIdentity.Models.Customer> Customers { get; set; } 

    public System.Data.Entity.DbSet<LocalIdentity.Models.Participant> Participants { get; set; } 

    public System.Data.Entity.DbSet<LocalIdentity.Models.File> Files { get; set; } 

    public System.Data.Entity.DbSet<LocalIdentity.Models.Family> Families { get; set; } 

    public System.Data.Entity.DbSet<LocalIdentity.Models.Procedure> Procedures { get; set; } 

    public System.Data.Entity.DbSet<LocalIdentity.Models.Vendor> Vendors { get; set; } 

    public System.Data.Entity.DbSet<LocalIdentity.Models.Log> Logs { get; set; } 

    public System.Data.Entity.DbSet<LocalIdentity.Models.Signature> Signatures { get; set; } 

    public System.Data.Entity.DbSet<LocalIdentity.Models.Receipt> Receipt { get; set; } 

    public System.Data.Entity.DbSet<LocalIdentity.Models.Department> Departments { get; set; } 


} 

這是我的遷移:

namespace LocalIdentity.Migrations 
{ 
    using System; 
    using System.Data.Entity.Migrations; 

    public partial class SignatureIdInUSerDeleted : DbMigration 
    { 
     public override void Up() 
     { 
      DropForeignKey("dbo.aspnetusers", "SignatureId", "dbo.Signatures"); 
      DropIndex("dbo.aspnetusers", new[] { "SignatureId" }); 
      DropColumn("dbo.aspnetusers", "FirstName"); 
      DropColumn("dbo.aspnetusers", "LastName"); 
      DropColumn("dbo.aspnetusers", "SignatureId"); 
     } 

     public override void Down() 
     { 
      AddColumn("dbo.aspnetusers", "SignatureId", c => c.Int()); 
      AddColumn("dbo.aspnetusers", "LastName", c => c.String(unicode: false)); 
      AddColumn("dbo.aspnetusers", "FirstName", c => c.String(unicode: false)); 
      CreateIndex("dbo.aspnetusers", "SignatureId"); 
      AddForeignKey("dbo.aspnetusers", "SignatureId", "dbo.Signatures", "Id", cascadeDelete: true); 
     } 
    } 
} 

我不不知道爲什麼我得到這個錯誤,如果我可以添加,我應該可以刪除。

+0

您在更新數據庫步驟中獲得了這個結果嗎?嘗試編寫腳本,以便可以看到生成的SQL。通常我懷疑連接字符串問題。 –

+0

謝謝,但我沒有連接字符串的問題,'因爲我可以添加表,添加列,但是,問題是當我想「改變」表,這個問題是與MySql,在Ms-Sql工作正常。 –

回答

3

我終於想通了,與移民問題是前綴「DBO」,我只是刪除所有這些和它的作品,我找到了答案here,我改變我的配置類這樣的:

public Configuration() 
    { 
     AutomaticMigrationsEnabled = true; 
     SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator()); 
     CodeGenerator = new MySql.Data.Entity.MySqlMigrationCodeGenerator(); //this line was missing, so now the migrations does not contains the prefix "dbo" 

    } 

現在遷移是自動生成的,沒有前綴「dbo」

public override void Up() 
    { 
     DropForeignKey("UserDatas", "UserId", "AspNetUsers"); 
     DropIndex("UserDatas", new[] { "UserId" }); 
     AlterColumn("UserDatas", "UserId", c => c.String(nullable: false, maxLength: 128, unicode: false, storeType: "nvarchar")); 
     AlterColumn("UserDatas", "FirstName", c => c.String(nullable: false, unicode: false)); 
     AlterColumn("UserDatas", "LastName", c => c.String(nullable: false, unicode: false)); 
     AlterColumn("UserDatas", "Title", c => c.String(nullable: false, unicode: false)); 
     CreateIndex("UserDatas", "UserId"); 
     AddForeignKey("UserDatas", "UserId", "AspNetUsers", "Id", cascadeDelete: true); 
    }