[X++] Alternative: Get rid of BP error 839: Only foreign key constraints are allowed on this table

Property EnforceFKRelation

When creating new tables in Dynamics AX 2012, there is a hidden property in the background called EnforceFKRelation.
This property defines if the tables enforces ForeignKey Relations or not and is set to 1 (True) on newly created tables.

This property does not appear anywhere in the AOT, so to check it the table needs to be exported as an XPO file. Open it with the editor of your choice:

EnforceFKRelation property

In line 11 you can see the property.

Related BP error 839

BestPractice error Message

Only foreign key constraints are allowed on this table

Example scenario

Let's assume we created a new table CustCollectionLetterLineTranslation and want to make a RecId relation to the standard table CustCollectionLetterLine.

CustCollectionLetterLine PrimaryKey

The PrimaryKey on the table CustCollectionLetterLine consists of three fields:
PrimaryKey on table CustCollectionLetterLine

So a relation would use those three fields to find exactly one record on this table.
There is no RecId index on this table!
properties no recid index

Relation on new table

Although there is no RecId index on the table CustCollectionLetterLine we want to create a relation using the RecId field. This would give us said best practice error.
new relation with RecId

The alternative way to make this relation a ForeignKey relation

Export the table as XPO file, open it with the editor of your choice and modify the section of the relation to have REFERENCETYPE PKFK
OLD:

...
REFERENCES
      REFERENCE #CustCollectionLetterLine
        PROPERTIES
          Name                #CustCollectionLetterLine
          Table               #CustCollectionLetterLine
          RelatedTableCardinality   #ExactlyOne
          Cardinality         #OneMore
          RelationshipType    #Aggregation
          UseDefaultRoleNames #Yes
        ENDPROPERTIES
        
        FIELDREFERENCES
          REFERENCETYPE NORMAL
          PROPERTIES
            Field               #CustCollectionLetterLine
            RelatedField        #RecId
          ENDPROPERTIES
          
        ENDFIELDREFERENCES
      ENDREFERENCE
...

NEW:

...
REFERENCES
      REFERENCE #CustCollectionLetterLine
        PROPERTIES
          Name                #CustCollectionLetterLine
          Table               #CustCollectionLetterLine
          RelatedTableCardinality   #ExactlyOne
          Cardinality         #OneMore
          RelationshipType    #Aggregation
          UseDefaultRoleNames #Yes
        ENDPROPERTIES
        
        FIELDREFERENCES
          REFERENCETYPE PKFK
          PROPERTIES
            Field               #CustCollectionLetterLine
            RelatedField        #RecId
          ENDPROPERTIES
          
        ENDFIELDREFERENCES
      ENDREFERENCE
...

Import it et voila, the best practice error is gone!