首页 > 解决方案 > 如何在 Django 中为历史表设置自动生成的元字段

问题描述

样品模型

from simple_history.models import HistoricalRecords()

class Sample(models.Model):
  company = models.CharField(max_length=100,null=True,blank=True)  
  history = HistoricalRecords()

在上面的模型中,我使用了HistoricalRecordsfrom django-simple-history来保存每个实例的更改历史Sample

问题

history_user无法填充错误消息:**Error** : 1452, 'Cannot add or update a child row: a foreign key constraint fails,REFERENCES auth_user (id)

如何在实例中设置history_change_reasonand ?history_user_idHistoricalRecords()

编辑:尝试过这个解决方案:链接

标签: djangopython-3.xdjango-modelsdjango-simple-history

解决方案


推荐阅读