Django use Integer Field as ForeignKey field
<p>To support old (legacy) db we have to create a table that using <strong>integer field</strong> as a <strong>foreignkey</strong> to <strong>User</strong> table: This is how our model look like:</p>

<pre><code>class UserHistory():
    user_id = models.IntegerField(null=True, blank=True)
    # ..... (other fields) .....
</code></pre>

<p>Problem is user id may or may not exist in User table. Is there any way to treat that user_id field as foreign key to user talbe (when it exist)? So I can dis play on django admin or other place instead of just the ID.</p>

<p>You can use a <code>ForeignKey</code> field with <code>db_constraint=False</code>. See the <a href="https://docs.djangoproject.com/en/1.10/ref/models/fields/#django.db.models.ForeignKey.db_constraint" rel="nofollow">docs</a> for warnings, but legacy invalid data is one of the cases where this is reasonable.</p>

python django django-models orm django-admin