{"id":204300,"date":"2020-11-24T04:36:19","date_gmt":"2020-11-23T20:36:19","guid":{"rendered":"http:\/\/4563.org\/?p=204300"},"modified":"2020-11-24T04:36:19","modified_gmt":"2020-11-23T20:36:19","slug":"typeorm-%e4%bd%bf%e7%94%a8-primarygeneratedcolumn-%e6%b3%a8%e8%a7%a3%e6%8a%a5%e9%94%99%e3%80%82%e3%80%82","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=204300","title":{"rendered":"TypeOrm \u4f7f\u7528 PrimaryGeneratedColumn \u6ce8\u89e3\u62a5\u9519\u3002\u3002"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  TypeOrm \u4f7f\u7528 PrimaryGeneratedColumn \u6ce8\u89e3\u62a5\u9519\u3002\u3002               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : cs3230524 <\/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>\u5c31\u5f88\u666e\u901a\u7684\u4e00\u4e2a\u5b9e\u4f53<\/p>\n<pre><code>@Entity() export class Spm {     @PrimaryGeneratedColumn()     \/\/@PrimaryGeneratedColumn(\"uuid\") \/\/\u8fd9\u4e2a\u6ca1\u95ee\u9898\uff0c\u53ef\u4ee5\u6b63\u5e38\u8fd0\u884c     id: number;     @Column()     type: string; }  <\/code><\/pre>\n<p>\u7136\u540e\u6267\u884c\u540e\u62a5\u8fd9\u4e2a\u9519\u8bef\uff0c\u5e76\u4e14\u63d2\u5165\u4e86\u4e00\u6761 id \u4e3a 0 \u7684\u6570\u636e\uff0c\u91cd\u590d\u6267\u884c\u4f9d\u65e7\u63d2\u5165 0\uff0c\u800c\u4e0d\u662f 1 \u3002<\/p>\n<pre><code>Error: Cannot update entity because entity id is not set in the entity. <\/code><\/pre>\n<p>\u8fd9\u4e2a\u9519\u8bef\u5728\u8fd9\u91cc 170 \u884c\u62a5\u51fa\uff1a<\/p>\n<pre><code>\/\/https:\/\/github.com\/typeorm\/typeorm\/blob\/c4a36da62593469436b074873eba186f0f8b990d\/src\/query-builder\/ReturningResultsEntityUpdator.ts#L119-L130 <\/code><\/pre>\n<p>\u540c\u6837\u7684\u4ee3\u7801\u5728 windows \u662f\u6ca1\u95ee\u9898\u7684\uff0c\u6240\u4ee5\u6211\u6000\u7591\u662f\u7cfb\u7edf\u73af\u5883\u95ee\u9898\uff1f<\/p>\n<p>\u76ee\u524d\u7684\u7cfb\u7edf\u73af\u5883\uff1a<\/p>\n<pre><code> | Operating System    | MacOS 10.15.4 | Node.js version     | v10.15.3  | @nestjs\/typeorm     | v^7.1.5 | Typescript version  | v^3.7.4  | TypeORM version     | v^0.2.29    <\/code><\/pre>\n<p>\u6c42\u5927\u795e\u6551\u6551&#8230;\u6211\u4eba\u90fd\u50bb\u4e86\u3002<\/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=\"4318096\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xiangwan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u68c0\u67e5\u4e0b\u4e3b\u952e\u6570\u636e\u7c7b\u578b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4318097\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Zchary <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u751f\u6210 schema \u4e86\u5417\uff1f\u6570\u636e\u5e93\u67e5\u4e0b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4318098\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : cs3230524 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Zchary \u6211\u6570\u636e\u90fd\u63d2\u8fdb\u53bb\u4e86\u80af\u5b9a\u751f\u6210\u4e86\u554a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4318099\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Zchary <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6307\u5b9a auoto increment \u8bd5\u8bd5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4318100\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : cs3230524 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Zchary \u6211\u90fd\u8bd5\u904d\u4e86 @PrimaryGeneratedColumn(&#8216;increment&#8217;)\u4e5f\u662f\u4e0d\u884c\u7684\uff0c\u53ea\u6709 uuid \u80fd\u7528\u3002\u540c\u6837\u7684\u4ee3\u7801\u5728 windows \u5c31\u6ca1\u95ee\u9898\uff0c\u8c03\u8bd5\u8ddf\u6e90\u7801\u627e\u4e0d\u5230\u4ed6\u7684 bug \u3002\u3002\u3002\u54ce\uff0c\u8fd9\u90fd\u5565\u7834\u6846\u67b6\u554a\uff0c\u8fde\u4e2a demo \u90fd\u8dd1\u4e0d\u4e86\uff0cissue \u4e5f\u6ca1\u4eba\u7ba1\u3002\u6211\u5f88\u65e0\u8bed\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4318101\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : cs3230524 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u5199\u4e00\u534a\u4e86\u4e5f\u4e0d\u53ef\u80fd\u6362\uff0c\u6015\u7684\u5c31\u662f\u751f\u4ea7\u73af\u5883\u51fa\u8fd9\u6837\u7684\u95ee\u9898\u6211\u5c31\u8981\u5012\u5927\u9709\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4318102\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hongweiliuruige <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u7a7f\u53c2\u6570\u9ed8\u8ba4\u5c31\u662f increment \u6570\u503c\u81ea\u589e\uff0c\u4f60\u542f\u52a8\u65f6\u8fd8\u4f1a\u63d2\u6570\u636e\uff1f\uff0c\u597d\u597d\u770b\u770b\u4f60\u4ee3\u7801\u628a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>TypeOrm \u4f7f\u7528 Primar&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\/204300"}],"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=204300"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/204300\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=204300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=204300"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=204300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}