Diana Lomeli Diana Lomeli - 3 months ago 208
MySQL Question

Table 'XXX.dbo.aspnetusers' doesn't exist, migrations VS-Mysql

I added some properties into ApplicationUser, now I want delete those properties, but I have this:

MySql.Data.MySqlClient.MySqlException (0x80004005): Table 'intranetproto.dbo.aspnetusers' doesn't exist.

this are the properties that I want delete:

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;
}

}

}


this is my Identity model(without some properties)

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; }


}


this my migration:

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);
}
}
}


I don't have idea why I'm getting this error, if I can add I should be able to delete.

Answer

I finally figured out, the problem with the migration is the prefix "dbo", I just delete all them and it works, I found the answer here, I change my configuration class to this:

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"

    }

now the migration are generated automatically without the prefix "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);
    }
Comments