Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Issue with Migration while changing Abp DTable schema #1064


User avatar
0
maharatha created

I was trying to move the AbpTables from dbo. to xxx. using the latest changes

protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder);

        modelBuilder.ChangeAbpTablePrefix<Tenant, Role, User>(string.Empty,"xxx");
    }

When I run the migration I get this issue while seeding :

Running Seed method. System.Data.SqlClient.SqlException (0x80131904): Cannot find the object "BackgroundJobs" because it does not exist or you do not have permissions.

ClientConnectionId:5c2bb018-df94-40df-8044-a3dc537b3e1a Error Number:4902,State:1,Class:16

Any Ideas ?


2 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Can you share the created migration code and table names in your database.

  • User Avatar
    0
    maharatha created

    namespace <<SOMENAME>>.<XXXX>>>.Migrations { using System; using System.Collections.Generic; using System.Data.Entity.Infrastructure.Annotations; using System.Data.Entity.Migrations;

    public partial class ForHilkan : DbMigration
    {
        public override void Up()
        {
            RenameTable(name: "dbo.&lt;&lt;SOMENAME&gt;>_Roles", newName: "Roles");
            RenameTable(name: "dbo.&lt;&lt;SOMENAME&gt;>_Users", newName: "Users");
            RenameTable(name: "dbo.&lt;&lt;SOMENAME&gt;>_OrganizationUnits", newName: "OrganizationUnits");
            RenameTable(name: "dbo.&lt;&lt;SOMENAME&gt;>_UserLogins", newName: "UserLogins");
            RenameTable(name: "dbo.&lt;&lt;SOMENAME&gt;>_Permissions", newName: "Permissions");
            RenameTable(name: "dbo.&lt;&lt;SOMENAME&gt;>_UserRoles", newName: "UserRoles");
            RenameTable(name: "dbo.&lt;&lt;SOMENAME&gt;>_Settings", newName: "Settings");
            RenameTable(name: "dbo.&lt;&lt;SOMENAME&gt;>_Tenants", newName: "Tenants");
            RenameTable(name: "dbo.&lt;&lt;SOMENAME&gt;>_Editions", newName: "Editions");
            RenameTable(name: "dbo.&lt;&lt;SOMENAME&gt;>_AuditLogs", newName: "AuditLogs");
            RenameTable(name: "dbo.&lt;&lt;SOMENAME&gt;>_BackgroundJobs", newName: "BackgroundJobs");
            RenameTable(name: "dbo.&lt;&lt;SOMENAME&gt;>_Features", newName: "Features");
            RenameTable(name: "dbo.&lt;&lt;SOMENAME&gt;>_Languages", newName: "Languages");
            RenameTable(name: "dbo.&lt;&lt;SOMENAME&gt;>_LanguageTexts", newName: "LanguageTexts");
            RenameTable(name: "dbo.&lt;&lt;SOMENAME&gt;>_Notifications", newName: "Notifications");
            RenameTable(name: "dbo.&lt;&lt;SOMENAME&gt;>_NotificationSubscriptions", newName: "NotificationSubscriptions");
            RenameTable(name: "dbo.&lt;&lt;SOMENAME&gt;>_UserLoginAttempts", newName: "UserLoginAttempts");
            RenameTable(name: "dbo.&lt;&lt;SOMENAME&gt;>_UserNotifications", newName: "UserNotifications");
            RenameTable(name: "dbo.&lt;&lt;SOMENAME&gt;>_UserOrganizationUnits", newName: "UserOrganizationUnits");
            MoveTable(name: "dbo.Roles", newSchema: "xxx");
            MoveTable(name: "dbo.Users", newSchema: "xxx");
            MoveTable(name: "dbo.OrganizationUnits", newSchema: "xxx");
            MoveTable(name: "dbo.UserLogins", newSchema: "xxx");
            MoveTable(name: "dbo.Permissions", newSchema: "xxx");
            MoveTable(name: "dbo.UserRoles", newSchema: "xxx");
            MoveTable(name: "dbo.Settings", newSchema: "xxx");
            MoveTable(name: "dbo.Tenants", newSchema: "xxx");
            MoveTable(name: "dbo.Editions", newSchema: "xxx");
            MoveTable(name: "dbo.AuditLogs", newSchema: "xxx");
            MoveTable(name: "dbo.BackgroundJobs", newSchema: "xxx");
            MoveTable(name: "dbo.Features", newSchema: "xxx");
            MoveTable(name: "dbo.Languages", newSchema: "xxx");
            MoveTable(name: "dbo.LanguageTexts", newSchema: "xxx");
            MoveTable(name: "dbo.Notifications", newSchema: "xxx");
            MoveTable(name: "dbo.NotificationSubscriptions", newSchema: "xxx");
            MoveTable(name: "dbo.UserLoginAttempts", newSchema: "xxx");
            MoveTable(name: "dbo.UserNotifications", newSchema: "xxx");
            MoveTable(name: "dbo.UserOrganizationUnits", newSchema: "xxx");
            CreateTable(
                "dbo.&lt;&lt;SOMENAME&gt;>_OrganizationUnits",
                c => new
                    {
                        Id = c.Long(nullable: false),
                        MyId = c.Int(),
                    },
                annotations: new Dictionary&lt;string, object&gt;
                {
                    { "DynamicFilter_OrganizationExtended_MayHaveTenant", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
                    { "DynamicFilter_OrganizationExtended_SoftDelete", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
                })
                .PrimaryKey(t => t.Id)
                .ForeignKey("xxx.OrganizationUnits", t => t.Id)
                .Index(t => t.Id);
            
            AlterTableAnnotations(
                "xxx.OrganizationUnits",
                c => new
                    {
                        Id = c.Long(nullable: false, identity: true),
                        TenantId = c.Int(),
                        ParentId = c.Long(),
                        Code = c.String(nullable: false, maxLength: 128),
                        DisplayName = c.String(nullable: false, maxLength: 128),
                        IsDeleted = c.Boolean(nullable: false),
                        DeleterUserId = c.Long(),
                        DeletionTime = c.DateTime(),
                        LastModificationTime = c.DateTime(),
                        LastModifierUserId = c.Long(),
                        CreationTime = c.DateTime(nullable: false),
                        CreatorUserId = c.Long(),
                    },
                annotations: new Dictionary&lt;string, AnnotationValues&gt;
                {
                    { 
                        "DynamicFilter_OrganizationExtended_MayHaveTenant",
                        new AnnotationValues(oldValue: "EntityFramework.DynamicFilters.DynamicFilterDefinition", newValue: null)
                    },
                    { 
                        "DynamicFilter_OrganizationExtended_SoftDelete",
                        new AnnotationValues(oldValue: "EntityFramework.DynamicFilters.DynamicFilterDefinition", newValue: null)
                    },
                });
            
            DropColumn("xxx.OrganizationUnits", "MyId");
            DropColumn("xxx.OrganizationUnits", "Discriminator");
        }
        
        public override void Down()
        {
            AddColumn("xxx.OrganizationUnits", "Discriminator", c => c.String(nullable: false, maxLength: 128));
            AddColumn("xxx.OrganizationUnits", "MyId", c => c.Int());
            DropForeignKey("dbo.&lt;&lt;SOMENAME&gt;>_OrganizationUnits", "Id", "xxx.OrganizationUnits");
            DropIndex("dbo.&lt;&lt;SOMENAME&gt;>_OrganizationUnits", new[] { "Id" });
            AlterTableAnnotations(
                "xxx.OrganizationUnits",
                c => new
                    {
                        Id = c.Long(nullable: false, identity: true),
                        TenantId = c.Int(),
                        ParentId = c.Long(),
                        Code = c.String(nullable: false, maxLength: 128),
                        DisplayName = c.String(nullable: false, maxLength: 128),
                        IsDeleted = c.Boolean(nullable: false),
                        DeleterUserId = c.Long(),
                        DeletionTime = c.DateTime(),
                        LastModificationTime = c.DateTime(),
                        LastModifierUserId = c.Long(),
                        CreationTime = c.DateTime(nullable: false),
                        CreatorUserId = c.Long(),
                    },
                annotations: new Dictionary&lt;string, AnnotationValues&gt;
                {
                    { 
                        "DynamicFilter_OrganizationExtended_MayHaveTenant",
                        new AnnotationValues(oldValue: null, newValue: "EntityFramework.DynamicFilters.DynamicFilterDefinition")
                    },
                    { 
                        "DynamicFilter_OrganizationExtended_SoftDelete",
                        new AnnotationValues(oldValue: null, newValue: "EntityFramework.DynamicFilters.DynamicFilterDefinition")
                    },
                });
            
            DropTable("dbo.&lt;&lt;SOMENAME&gt;>_OrganizationUnits",
                removedAnnotations: new Dictionary&lt;string, object&gt;
                {
                    { "DynamicFilter_OrganizationExtended_MayHaveTenant", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
                    { "DynamicFilter_OrganizationExtended_SoftDelete", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
                });
            MoveTable(name: "xxx.UserOrganizationUnits", newSchema: "dbo");
            MoveTable(name: "xxx.UserNotifications", newSchema: "dbo");
            MoveTable(name: "xxx.UserLoginAttempts", newSchema: "dbo");
            MoveTable(name: "xxx.NotificationSubscriptions", newSchema: "dbo");
            MoveTable(name: "xxx.Notifications", newSchema: "dbo");
            MoveTable(name: "xxx.LanguageTexts", newSchema: "dbo");
            MoveTable(name: "xxx.Languages", newSchema: "dbo");
            MoveTable(name: "xxx.Features", newSchema: "dbo");
            MoveTable(name: "xxx.BackgroundJobs", newSchema: "dbo");
            MoveTable(name: "xxx.AuditLogs", newSchema: "dbo");
            MoveTable(name: "xxx.Editions", newSchema: "dbo");
            MoveTable(name: "xxx.Tenants", newSchema: "dbo");
            MoveTable(name: "xxx.Settings", newSchema: "dbo");
            MoveTable(name: "xxx.UserRoles", newSchema: "dbo");
            MoveTable(name: "xxx.Permissions", newSchema: "dbo");
            MoveTable(name: "xxx.UserLogins", newSchema: "dbo");
            MoveTable(name: "xxx.OrganizationUnits", newSchema: "dbo");
            MoveTable(name: "xxx.Users", newSchema: "dbo");
            MoveTable(name: "xxx.Roles", newSchema: "dbo");
            RenameTable(name: "dbo.UserOrganizationUnits", newName: "&lt;&lt;SOMENAME&gt;>_UserOrganizationUnits");
            RenameTable(name: "dbo.UserNotifications", newName: "&lt;&lt;SOMENAME&gt;>_UserNotifications");
            RenameTable(name: "dbo.UserLoginAttempts", newName: "&lt;&lt;SOMENAME&gt;>_UserLoginAttempts");
            RenameTable(name: "dbo.NotificationSubscriptions", newName: "&lt;&lt;SOMENAME&gt;>_NotificationSubscriptions");
            RenameTable(name: "dbo.Notifications", newName: "&lt;&lt;SOMENAME&gt;>_Notifications");
            RenameTable(name: "dbo.LanguageTexts", newName: "&lt;&lt;SOMENAME&gt;>_LanguageTexts");
            RenameTable(name: "dbo.Languages", newName: "&lt;&lt;SOMENAME&gt;>_Languages");
            RenameTable(name: "dbo.Features", newName: "&lt;&lt;SOMENAME&gt;>_Features");
            RenameTable(name: "dbo.BackgroundJobs", newName: "&lt;&lt;SOMENAME&gt;>_BackgroundJobs");
            RenameTable(name: "dbo.AuditLogs", newName: "&lt;&lt;SOMENAME&gt;>_AuditLogs");
            RenameTable(name: "dbo.Editions", newName: "&lt;&lt;SOMENAME&gt;>_Editions");
            RenameTable(name: "dbo.Tenants", newName: "&lt;&lt;SOMENAME&gt;>_Tenants");
            RenameTable(name: "dbo.Settings", newName: "&lt;&lt;SOMENAME&gt;>_Settings");
            RenameTable(name: "dbo.UserRoles", newName: "&lt;&lt;SOMENAME&gt;>_UserRoles");
            RenameTable(name: "dbo.Permissions", newName: "&lt;&lt;SOMENAME&gt;>_Permissions");
            RenameTable(name: "dbo.UserLogins", newName: "&lt;&lt;SOMENAME&gt;>_UserLogins");
            RenameTable(name: "dbo.OrganizationUnits", newName: "&lt;&lt;SOMENAME&gt;>_OrganizationUnits");
            RenameTable(name: "dbo.Users", newName: "&lt;&lt;SOMENAME&gt;>_Users");
            RenameTable(name: "dbo.Roles", newName: "&lt;&lt;SOMENAME&gt;>_Roles");
        }
    }
    

    }