Installation Plugin: There is already an object named 'Address' in the database.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
Hey,
I'm trying to install my plugin and get the following error message:
There is already an object named 'Address' in the database.


I do not understand the problem, because I only add 2 new entities. They are not even using the Address table.
Can somebody help me?

Update: I debugged the sql script which is generated: The generated script tries to CREATE a bunch of existing tables such as Address, Category, Customer and many more.

My custom entities I want to add look like:

  
    
    public class DiscountEntry : BaseEntity
    {
        public int Quantity { get; set; }
        public decimal Discount { get; set; }
    }


    public class DiscountGroup : BaseEntity
    {
        public virtual ICollection<Product> Products { get; set; }
        public virtual ICollection<DiscountEntry> DiscountEntries { get; set; }
        public DateTime DiscountFrom { get; set; }
        public DateTime DiscountUntil { get; set; }
    }


Can anybody see the problem?

Thank you in advance!

Best regards
7 years ago
BigBabyJesus wrote:
Hey,
I'm trying to install my plugin and get the following error message:
There is already an object named 'Address' in the database.


I do not understand the problem, because I only add 2 new entities. They are not even using the Address table.
Can somebody help me?

Update: I debugged the sql script which is generated: The generated script tries to CREATE a bunch of existing tables such as Address, Category, Customer and many more.

My custom entities I want to add look like:

  
    
    public class DiscountEntry : BaseEntity
    {
        public int Quantity { get; set; }
        public decimal Discount { get; set; }
    }


    public class DiscountGroup : BaseEntity
    {
        public virtual ICollection<Product> Products { get; set; }
        public virtual ICollection<DiscountEntry> DiscountEntries { get; set; }
        public DateTime DiscountFrom { get; set; }
        public DateTime DiscountUntil { get; set; }
    }


Can anybody see the problem?

Thank you in advance!

Best regards


Check your db context

Go through ==>Nop.Plugin.Feed.Froogle

Hope it will help you.
7 years ago
Actually I already did.
Here is a snippet of my DB Context:


public class DiscountContext : DbContext, IDbContext
    {
        #region Ctor

        public DiscountContext(string nameOrConnectionString)
            : base(nameOrConnectionString)
        {
            //((IObjectContextAdapter) this).ObjectContext.ContextOptions.LazyLoadingEnabled = true;
        }

        #endregion

        #region Utilities

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new DiscountGroupMap());
            modelBuilder.Configurations.Add(new DiscountEntryMap());

            //disable EdmMetadata generation
            //modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            base.OnModelCreating(modelBuilder);
        }


        #endregion

        #region Methods

        public string CreateDatabaseScript()
        {
            return ((IObjectContextAdapter)this).ObjectContext.CreateDatabaseScript();
        }

        public new IDbSet<TEntity> Set<TEntity>() where TEntity : BaseEntity
        {
            return base.Set<TEntity>();
        }

        /// <summary>
        /// Install
        /// </summary>
        public void Install()
        {
            //create the table
            var dbScript = CreateDatabaseScript();
            Database.ExecuteSqlCommand(dbScript);
            SaveChanges();
        }

        /// <summary>
        /// Uninstall
        /// </summary>
        public void Uninstall()
        {
            //drop the tables
            var tableName1 = this.GetTableName<DiscountGroup>();
            var tableName2 = this.GetTableName<DiscountEntry>();

            this.DropPluginTable(tableName1);
            this.DropPluginTable(tableName2);
        }


Can you see any troublemaker?

Thanks!
7 years ago
After trying some possible solutions, I removed the virtual collection of Nop.Core.Domain.Catalog.Product.
The products are now just linked via their Ids.

The now look like this:


    public class DiscountGroup : BaseEntity
    {
        public ICollection<int> ProductIds { get; set; }
        public virtual ICollection<DiscountEntry> DiscountEntries { get; set; }
        public DateTime DiscountFrom { get; set; }
        public DateTime DiscountUntil { get; set; }
    }

    public class DiscountEntry : BaseEntity
    {
        public int Quantity { get; set; }
        public decimal Discount { get; set; }
    }


Well, that works for me.
But I do not understand what EF is doing behind the scenes when adding a property of existing entities.

Cheers!
7 years ago
BigBabyJesus wrote:
After trying some possible solutions, I removed the virtual collection of Nop.Core.Domain.Catalog.Product.
The products are now just linked via their Ids.

The now look like this:


    public class DiscountGroup : BaseEntity
    {
        public ICollection<int> ProductIds { get; set; }
        public virtual ICollection<DiscountEntry> DiscountEntries { get; set; }
        public DateTime DiscountFrom { get; set; }
        public DateTime DiscountUntil { get; set; }
    }

    public class DiscountEntry : BaseEntity
    {
        public int Quantity { get; set; }
        public decimal Discount { get; set; }
    }


Well, that works for me.
But I do not understand what EF is doing behind the scenes when adding a property of existing entities.

Cheers!


Check your dependency register too.
2 years ago
I have same problem in nopCommerce 4.1, my temp solution is to  use manually writen Sql script. Is there any smart solution for this?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.