{"id":710,"date":"2023-02-26T15:14:37","date_gmt":"2023-02-26T07:14:37","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=710"},"modified":"2023-04-29T17:16:58","modified_gmt":"2023-04-29T09:16:58","slug":"greendao-insert-solve-primary-key-must-be-unique","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/26\/greendao-insert-solve-primary-key-must-be-unique\/","title":{"rendered":"GreenDao insert \u89e3\u51b3 PRIMARY KEY must be unique"},"content":{"rendered":"<ol>\n<li>\n<p>\u5982\u679c\u4e3b\u952e\u6807\u8bb0\u65f6\u6ca1\u6709\u6dfb\u52a0autoincrement\uff0c\u90a3\u4e48\u5c31\u662f\u4f20\u7684id\u91cd\u590d\u4e86, \u4f20\u7684\u65f6\u5019\u83b7\u53d6\u6700\u65b0id\u7136\u540e++id\u5373\u53ef<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u6807\u8bb0<code>@Id(autoincrement = true)<\/code>\uff0c\u6309\u7406\u4e0d\u7528\u624b\u52a8\u4f20id\u7684\uff0c\u4e5f\u786e\u5b9e\u6ca1\u4f20\uff0c\u8fd8\u62a5not unique\u7684\u8bdd\uff0c\u90a3\u4e48 GreenDao\u7684\u4e3b\u952e\u5fc5\u987b\u8bbe\u7f6e\u6210\u5305\u88c5\u7c7b Long<\/p>\n<\/li>\n<\/ol>\n<p><!-- more --><\/p>\n<pre><code class=\"language-java\">@Id(autoincrement = true)\nprivate long _id;<\/code><\/pre>\n<p>\u7ed3\u8bba\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u4e3b\u952e\u8bbe\u7f6e\u4e3a\u5305\u88c5\u7c7bLong\u7c7b\u578b\uff0c\u90a3\u4e48\u5728\u751f\u6210\u7684Dao\u7c7b\u4e2d\u4f1a\u6709\u4e00\u4e2a\u5224\u65ad\u4e3anull\u624d\u63d2\u5165\uff0c\u975enull\u5219\u66f4\u65b0<\/li>\n<li>\u5982\u679c\u662flong\u7c7b\u578b\uff0c\u5373\u4f7f\u4e0d\u4f20\u503c\uff0c\u4e5f\u4f1ainsert _id = 0\uff0c\u4e8e\u662f\u62a5\u5f02\u5e38<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u4e3b\u952e\u6807\u8bb0\u65f6\u6ca1\u6709\u6dfb\u52a0autoincrement\uff0c\u90a3\u4e48\u5c31\u662f\u4f20\u7684id\u91cd\u590d\u4e86, \u4f20\u7684\u65f6\u5019\u83b7\u53d6\u6700\u65b0id\u7136\u540e++id\u5373 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[205],"tags":[204],"class_list":["post-710","post","type-post","status-publish","format-standard","hentry","category-android-database-library","tag-greendao"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/710","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=710"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/710\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}