Inhalte aufrufen

Profilbild

automatically update database on plugin installation not working


  • Bitte melden Sie sich an, um eine Antwort zu verfassen.
2 Antworten zu diesem Thema

#1 mohsenns5

mohsenns5

    Newbie

  • Members
  • Punkt
  • 4 Beiträge

Geschrieben: 16 June 2017 - 09:52

In my plugin uninstallation, the database update successfully(remove [myTable]). But on the plugin installation, the database not update automatically(not generate [myTable]). Please help me to find problem.

    internal sealed class Configuration : DbMigrationsConfiguration<myStoreObjectContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
            MigrationsDirectory = @"Data\Migrations";
			ContextKey = "ArvinTech.myStore";
        }

        protected override void Seed(myStoreObjectContext context)
        {
         
        }
    }
  public class myStoreObjectContext : ObjectContextBase
    {
        public const string ALIASKEY = "sm_object_context_my_store_zip";
        
		static myStoreObjectContext()
		{
			var initializer = new MigrateDatabaseInitializer<myStoreObjectContext, Configuration>
			{
				TablesToCheck = new[] { "myFeature" }
			};
			Database.SetInitializer(initializer);
		}

		/// <summary>
		/// For tooling support, e.g. EF Migrations
		/// </summary>
		public myStoreObjectContext()
			: base()
		{
		}

        public myStoreObjectContext(string nameOrConnectionString)
            : base(nameOrConnectionString, ALIASKEY)
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new myFeatureMap());
            base.OnModelCreating(modelBuilder);
        }
       
    }
   public partial class Initial : DbMigration
    {
        public override void Up()
        {
            if (DbMigrationContext.Current.SuppressInitialCreate<myStoreObjectContext>())
                return;

            CreateTable(
                "dbo.myFeature",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 400),
                        FullName = c.String(maxLength: 400),
                        Description = c.String(),
                        Alias = c.String(maxLength: 100),
                        Published = c.Boolean(nullable: false),
                        Deleted = c.Boolean(nullable: false),
                        DisplayOrder = c.Int(nullable: false),
                        CreatedOnUtc = c.DateTime(nullable: false),
                        UpdatedOnUtc = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
        }
        
        public override void Down()
        {
            DropTable("dbo.myFeature");
        }
    }

Thanks



#2 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3801 Beiträge

Geschrieben: 16 June 2017 - 12:00

A plugin related migration is executed when its entities are accessed for the first time and not when the plugin is installed.
After installing your plugin, "touch" your plugin entities and check whether the database table is created.
 
Please also check this documentation.

  • mohsenns5 gefällt das

Marcus Gesing

Smartstore AG


#3 mohsenns5

mohsenns5

    Newbie

  • Members
  • Punkt
  • 4 Beiträge

Geschrieben: 16 June 2017 - 14:14

Yes, right.

Thanks a lot.