【发布时间】:2019-11-26 11:59:20
【问题描述】:
我有一个简单的数据库视图,它从位于同一 MSSQL 服务器上的其他数据库表中进行选择,最终将收集到的信息作为下拉列表提供给用户。
到目前为止,我已经使用 inspectdb 添加了模型:
class AutPricePlanView(models.Model):
priceplan_name = models.CharField(db_column='PricePlan', max_length=50, blank=True, unique=True)
class Meta:
managed = False # Created from a view. Don't remove.
db_table = 'AUT_PricePlanView'
我还有第二个现有的(Django Native)模型,我想将视图中的值用于下拉字段(以保持所有内容同步):
class PricePlanDownload(models.Model):
requesting_user = models.CharField(blank=True, default=None, max_length=50, null=True)
requested_at = models.DateTimeField(auto_now_add=True)
document = models.FileField(upload_to='documents/price_plan_uploads/%Y/%m/%d', blank=True)
priceplan = models.ForeignKey(AutPricePlanView, null=True, on_delete=models.DO_NOTHING)
Makemigrations 工作正常,但是当我尝试实际迁移时,我遇到了以下问题:(缩短了一点) django.db.utils.ProgrammingError: ('42000', "[42000] [FreeTDS][SQL Server]外键引用不是用户表的对象'AUT_PricePlanView'。(1768) (SQLExecDirectW)")
如果有人有想法或解决方法,我将非常感激,因为我无法弄清楚这与“用户”表有什么关系......
【问题讨论】:
标签: django django-models