문제

I have to work with a legacy database and have the following problem. My model has a foreign key to the User Model:

class History(models.Model):
    uid = models.ForeignKey(User, to_field='username', db_column='uid')

That seems to work. The Problem is that for some History entries the User entry doesn't exist anymore. Is there an easy solution?

The Application seems to work fine with it. The only problem is in the Admin-Interface of the Model:

class HistoryAmdin(admin.ModelAdmin):
    list_display = ('id', 'uid')

It shows only entries with a valid foreign key. Is it possible to show also the other entries?

도움이 되었습니까?

해결책

Set you null=True inside your History class.

class History(models.Model):  
    uid = models.ForeignKey(User, to_field='username', db_column='uid', null=True)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top