什么是关系映射?
一对一:
一对一创建数据:
例:
python3 manage.py shell
Python 3.11.8 (v3.11.8:db85d51d3e, Feb 6 2024, 18:02:37) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from oto.models import *
>>> a1 = Author.objects.create(name="wang")
>>> w1 = Wife.objects.create(name = 'wangfuren',author = a1)
>>> a1 = Author.objects.create(name="bai")
>>> w1 = Wife.objects.create(name = 'baifuren',author_id = 2)
一对一数据查询:
一对多:
一对多创建:
一对多创建数据:
一对多-查询数据:
多对多:
多对多-创建
多对多-创建数据:
多对多-查询: