The ALTER TABLE statement conflicted with the FOREIGN KEY co

Posted by Community Admin on 04-Aug-2018 20:44

The ALTER TABLE statement conflicted with the FOREIGN KEY constraint

All Replies

Posted by Community Admin on 07-Mar-2012 00:00

We upgraded from sitefinity 4.3 to 4.4 and i get an error on a custom module that was outsourced

 

personConfiguration.HasAssociation(p => p.Functions).WithOpposite(f => f.Persons)

                 .MapJoinTable("PM_Person_Function", (person, function) => new
                 
                     PM_Person_ID = person.Id,
                     PM_Function_ID = function.Id
                 ).HasSequenceColumn("PM_Person_Function_ID", "Int"); 

The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "ref_PM_Prsn_Function_PM_Person". The conflict occurred in database "PromaxBDA", table "dbo.PM_Person", column 'PM_Person_ID'.

Posted by Community Admin on 12-Mar-2012 00:00

Hello,

 Review the tables created by the custom modules in the database (the error indicates pm_person). The foreign key constraint prevents the table to be updated or deleted. Check if there are any constraints in the Fluent Mapping of the module and check which entry in the database is conflicting with the foreign key. I suppose it is one module item creating the problem.

Kind regards,
Stanislav Velikov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 12-Mar-2012 00:00

here is all the mapping code, im still having problems

IList<MappingConfiguration> personsConfigurations = new List<MappingConfiguration>();
           MappingConfiguration<Person> personConfiguration = new MappingConfiguration<Person>();
           personConfiguration.MapType(p => new
           
               PM_Person_ID = p.Id,
               AuthenticationId = p.AuthenticationId,
               Prefix = p.Prefix,
               First_Name = p.FirstName,
               Last_Name = p.LastName,
               Middle_Name = p.MiddleName,
               Suffix = p.Suffix,
               eMailAddress = p.Email,
               Bio = p.Bio,
               DisplayFunction = p.DisplayFunction,
               Created_Datetime_UTC = p.DateCreatedUTC,
               Last_Update_Datetime_UTC = p.DateModifiedUTC,
               Last_Updated_by = p.ModifiedBy,
               ImageThumbnailID = p.ThumbnailID
           ).ToTable("PM_Person");
 
           personConfiguration.HasProperty(p => p.Id).IsIdentity(KeyGenerator.Autoinc);
           personConfiguration.HasProperty(p => p.Bio).HasColumnType("varchar(MAX)");
           personConfiguration.HasProperty(p => p.Prefix).HasLength(5).IsNullable();
           personConfiguration.HasProperty(p => p.Suffix).HasLength(5).IsNullable();
           personConfiguration.HasProperty(p => p.AuthenticationId).IsNullable();
           personConfiguration.HasProperty(p => p.DateModifiedUTC).IsNullable();
           //personConfiguration.HasProperty(p => p.DateCreatedUTC).IsCalculatedOn(
           //    DateTimeAutosetMode.Insert);
           //personConfiguration.HasProperty(p => p.DateModifiedUTC).IsNullable().IsCalculatedOn(
           //   DateTimeAutosetMode.Update);
           //personConfiguration.HasAssociation(p => p.Positions).WithOpposite(pos => pos.Person).HasConstraint((pos, p) => pos.)
 
           //personConfiguration.HasAssociation(p => p.Thumbnail).ToColumn("ThumbnailImageID");
            
 
           MappingConfiguration<Position> positionConfiguration = new MappingConfiguration<Position>();
           positionConfiguration.MapType(pos => new
           
               PM_Person_Position_ID = pos.Id,
               CurrentPosition = pos.CurrentPosition,
               Company_Name = pos.CompanyName,
               Position_Title = pos.Title,
               Display_Order = pos.DisplayOrder,
               PM_Person_ID = pos.PersonId
           ).ToTable("PM_Person_Position");
 
           positionConfiguration.HasProperty(p => p.Id).IsIdentity(KeyGenerator.Autoinc);
           positionConfiguration.HasAssociation(ps => ps.Person).WithOpposite(p => p.Positions).HasConstraint(
               (ps, p) => ps.PersonId == p.Id).IsManaged();
 
           MappingConfiguration<Function> functionConfiguration = new MappingConfiguration<Function>();
           functionConfiguration.MapType(f => new
           
               PM_Function_ID = f.Id,
               Title = f.Title,
               Locked_Function = f.Locked,
               Description = f.Description,
               IsCommittee = f.IsCommittee,
               CommitteePosition = f.CommitteePosition
           ).ToTable("PM_Function");
 
           functionConfiguration.HasProperty(f => f.Id).IsIdentity(KeyGenerator.Autoinc);
           functionConfiguration.HasProperty(f => f.Description).HasColumnType("nvarchar(MAX)");
 
           personConfiguration.HasAssociation(p => p.Functions).WithOpposite(f => f.Persons)
                .MapJoinTable("PM_Person_Function", (person, function) => new
                
                    PM_Person_ID = person.Id,
                    PM_Function_ID = function.Id
                ).HasSequenceColumn("PM_Person_Function_ID", "Int");

Posted by Community Admin on 03-Mar-2013 00:00

Hi Stephen,

Hope you resolved your issue. Could you please share with me some sample code for selector you used for such association? I can send you my email if necessary.

Thanks,
Denis.

This thread is closed