zoukankan      html  css  js  c++  java
  • 【Python】 Django 怎么实现 联合主键?

    unique_together

    Options.unique_together

    Sets of field names that, taken together, must be unique:

    unique_together = (("driver", "restaurant"),)
    

    This is a tuple of tuples that must be unique when considered together. It’s used in the Django admin and is enforced at the database level (i.e., the appropriate UNIQUE statements are included in the CREATE TABLEstatement).

    For convenience, unique_together can be a single tuple when dealing with a single set of fields:

    unique_together = ("driver", "restaurant")
    

    ManyToManyField cannot be included in unique_together. (It’s not clear what that would even mean!) If you need to validate uniqueness related to a ManyToManyField, try using a signal or an explicit through model.

    The ValidationError raised during model validation when the constraint is violated has the unique_together error code.

    参考资料:

    https://docs.djangoproject.com/en/dev/ref/models/options/#unique-together

    http://m.blog.csdn.net/article/details?id=8768504

  • 相关阅读:
    模块
    匿名函数
    推导式
    函数 重点
    新的
    知识点补充
    unity学习规划与进度
    暂停·笔记
    解决问题__max 模型白色 材质球换没用
    Max__cs骨骼
  • 原文地址:https://www.cnblogs.com/junneyang/p/6040012.html
Copyright © 2011-2022 走看看