【问题标题】:Django Multi-table Inheritance, Django-model-utils errorsDjango 多表继承,Django-model-utils 错误
【发布时间】:2012-04-18 02:16:10
【问题描述】:

我正在为我的车库商店做一个爱好项目。我被引导到 django-model-utils 来满足我的需要。 (我有串口CNC机,串口机有两种流控方式)

我有一个 SerialMachine 的父类(定义地址、波特率、通用 RS-232 定义)

然后我有继承自 SerialMachine 的 HardwareFlowControlMachine 模型(定义 CTS/DTR/等)

因此,当我将机器名称放入表单(例如机器 001)时,我有一个获取机器设置的功能。

def getMachineSettings(machine):

    from src.apps.cnc.models import SerialMachine

    machineSettings = SerialMachine.objects.get(machineName=machine).select_subclasses()

    return machineSettings

我得到了这个例外:

  DatabaseError: no such column: cnc_hardwareflowcontrolmachine.serialmachine_ptr_id

现在为了测试,我在 SoftwareFlowControlMachine 中只有一台机器(硬件中没有)

我想也许 HardwareFlowControlMachine 出于某种原因至少需要一个对象。因此,当我转到 /admin/ 并尝试将机器添加到 SoftwareFlowControlMachine 或 HardwareFlowControlMachine 时,我得到了这个异常:

硬件流控制机器:

DatabaseError at /admin/cnc/hardwareflowcontrolmachine/

no such column: cnc_hardwareflowcontrolmachine.serialmachine_ptr_id

Request Method:     GET
Request URL:    http://127.0.0.1:8000/admin/cnc/hardwareflowcontrolmachine/
Django Version:     1.4
Exception Type:     DatabaseError
Exception Value:    

no such column: cnc_hardwareflowcontrolmachine.serialmachine_ptr_id

Exception Location:     C:\Python27\lib\site-packages\django\db\backends\sqlite3\base.py in execute, line 337
Python Executable:  C:\Python27\python.exe
Python Version:     2.7.2

软件流控制机器:

DatabaseError at /admin/cnc/softwareflowcontrolmachine/

no such column: cnc_softwareflowcontrolmachine.serialmachine_ptr_id

Request Method:     GET
Request URL:    http://127.0.0.1:8000/admin/cnc/softwareflowcontrolmachine/
Django Version:     1.4
Exception Type:     DatabaseError
Exception Value:    

no such column: cnc_softwareflowcontrolmachine.serialmachine_ptr_id

Exception Location:     C:\Python27\lib\site-packages\django\db\backends\sqlite3\base.py in execute, line 337
Python Executable:  C:\Python27\python.exe
Python Version:     2.7.2

如果我需要提供更多信息,请告诉我。我真的不确定我错过了什么

【问题讨论】:

    标签: django inheritance multi-table


    【解决方案1】:

    我让它工作了。我仍然不清楚它为什么会发生。我犯的一个错误是而不是

     machineSettings = SerialMachine.objects.get(machineName=machine).select_subclasses()
    

    我需要这个

     machineSettings = SerialMachine.objects.get_subclass(machineName=machine)
    

    我也刚刚删除了我的数据库并重新制作了它。

    希望这对其他人也有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-08
      • 2011-03-16
      • 2012-12-17
      • 1970-01-01
      相关资源
      最近更新 更多