{"id":315999,"date":"2021-02-04T02:55:42","date_gmt":"2021-02-03T18:55:42","guid":{"rendered":"http:\/\/4563.org\/?p=315999"},"modified":"2021-02-04T02:55:42","modified_gmt":"2021-02-03T18:55:42","slug":"django-%e5%b8%a6%e5%a4%96%e9%94%ae%e6%a8%a1%e5%9e%8b-create-%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=315999","title":{"rendered":"django \u5e26\u5916\u952e\u6a21\u578b create \u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  django \u5e26\u5916\u952e\u6a21\u578b create \u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lixuda <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>from django.db import models<\/p>\n<p>class Blog(models.Model): # &#8230; pass<\/p>\n<p>class Entry(models.Model): blog = models.ForeignKey(Blog, on_delete=models.CASCADE,db_constraint=False)<\/p>\n<p>\u5f53 db_constraint=False \u65f6\uff0c \u4fdd\u5b58\u4e5f\u5fc5\u987b\u8981\u8c03\u7528 Model \u5417\uff1f Entry.objects.create(Blog(id=1)) \u6709\u6ca1\u6709\u80fd\u76f4\u63a5\u503c\u4f20\u5165\u5417\uff1f Entry.objects.create(blog=1)<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>7<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5188796\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : johnsona <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5927\u5382\u90fd\u662f\u4e0d\u5141\u8bb8\u5e94\u7528\u6846\u67b6\u4ee3\u7801\u76f4\u63a5\u7ebf\u4e0a ddl\uff0c\u4e5f\u5c31\u662f django \u7684 migrage\uff0c\u51fa\u95ee\u9898\u8fd9\u9505\u662f\u4f60\u5f00\u53d1\u80cc\u8fd8\u662f\u4eba\u8fd0\u7ef4\u80cc<br \/>\u90fd\u662f\u5f00\u53d1\u628a sql \u7ed9\u5230 dba \u53bb\u6267\u884c<br \/>\u5982\u679c\u5c0f\u5382\uff0c\u7ba1\u4ed6\u5916\u952e\u5462\uff0c\u8bf4\u5f97\u6709\u591a\u5927\u6d41\u91cf\u4f3c\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5188797\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : pepesii <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @johnsona #1 \u4eba\u5bb6\u5c31\u95ee\u4e2a\u95ee\u9898\uff0c\u5f88\u660e\u663e\u4eba\u5bb6\u662f\u521d\u5b66\u8005\uff0c\u4f60\u975e\u8981\u7b54\u975e\u6240\u95ee                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5188798\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : pepesii <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Entry.objects.create(blog_id=1, **kwargs)                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5188799\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : johnsona <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @pepesii \u9171\u7d2b\u7684\u5417 \u6211\u7684\u610f\u601d\u662f\u4e0d\u8981\u7528\u90a3\u4e2a db_condtraint \u8be5\u600e\u4e48\u6765\u600e\u4e48\u6765 \u4e0d\u7528\u4ed6\u8fc1\u79fb\u5c31\u597d\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5188800\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : lixuda <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @johnsona \u4e0d\u7528 db_condtraint\uff0cjoin \u597d\u50cf\u65e0\u6cd5\u64cd\u4f5c\uff1f\u624b\u5199 sql \uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5188801\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : lixuda <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @pepesii \u611f\u8c22\uff0c\u5df2\u89e3\u51b3                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5188802\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zoharSoul <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lixuda \u4ed6\u7684\u610f\u601d\u662f\u624b\u52a8\u5efa\u8868                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>django \u5e26\u5916\u952e\u6a21\u578b crea&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/315999"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=315999"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/315999\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=315999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=315999"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=315999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}