+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / The ALTER TABLE statement conflicted with the FOREIGN KEY constraint

The ALTER TABLE statement conflicted with the FOREIGN KEY constraint

4 posts, 0 answered
  1. Stephen
    Stephen avatar
    15 posts
    Registered:
    06 Oct 2011
    07 Mar 2012
    Link to this post
    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'.

  2. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    08 Dec 2016
    12 Mar 2012
    Link to this post
    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
  3. Stephen
    Stephen avatar
    15 posts
    Registered:
    06 Oct 2011
    12 Mar 2012
    Link to this post
    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");
  4. Denis
    Denis avatar
    105 posts
    Registered:
    27 Feb 2009
    03 Mar 2013 in reply to Stephen
    Link to this post

    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.

4 posts, 0 answered