{"id":10554,"date":"2022-09-06T17:07:03","date_gmt":"2022-09-06T09:07:03","guid":{"rendered":"https:\/\/www.gbase8.cn\/?p=10554"},"modified":"2022-09-06T17:07:04","modified_gmt":"2022-09-06T09:07:04","slug":"gbase-8a%e5%a2%9e%e5%8a%a0%e5%88%97%e6%97%b6%e6%8a%a5column-cannot-be-null%e6%88%96-doesnt-have-a-default-value%e9%94%99%e8%af%af","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/10554","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a\u589e\u52a0\u5217\u65f6\u62a5Column cannot be null\u6216 doesn't have a default value\u9519\u8bef"},"content":{"rendered":"<p>GBase 8a\u652f\u6301\u589e\u52a0\u65b0\u7684\u5217\uff0c\u5f53\u65b0\u589e\u5217\u6307\u5b9a\u4e86not null\u4e0d\u8bb8\u4e3anull\u65f6\uff0c\u5219\u5fc5\u987b\u6307\u5b9adefault\u9ed8\u8ba4\u503c\uff0c\u5426\u5219\u5c31\u4f1a\u62a5Column cannot be null\u6216 doesn't have a default value\u9519\u8bef\u3002<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Directory Navigation<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2aa1349c819\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2aa1349c819\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.gbase8.cn\/en\/10554\/#%E6%8A%A5%E9%94%99%E6%A0%B7%E4%BE%8B\" >\u62a5\u9519\u6837\u4f8b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.gbase8.cn\/en\/10554\/#%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88\" >Solution<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%8A%A5%E9%94%99%E6%A0%B7%E4%BE%8B\"><\/span>\u62a5\u9519\u6837\u4f8b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"776\" height=\"74\" src=\"https:\/\/www.gbase8.cn\/wp-content\/uploads\/2022\/09\/1662455097617.png\" alt=\"\" class=\"wp-image-10555\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>gbase> desc t1;\r\n+-------+---------------+------+-----+---------+-------+\r\n| Field | Type          | Null | Key | Default | Extra |\r\n+-------+---------------+------+-----+---------+-------+\r\n| id    | bigint(20)    | YES  |     | NULL    |       |\r\n| num   | decimal(20,0) | YES  |     | NULL    |       |\r\n+-------+---------------+------+-----+---------+-------+\r\n2 rows in set (Elapsed: 00:00:00.07)\r\n\r\ngbase> alter table t1 add address varchar(100) not null;\r\nERROR 1702 (HY000): gcluster table error: Column 'address' cannot be null.\r\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88\"><\/span>Solution<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u65e2\u7136\u65b0\u589e\u7684\u5217\u4e0d\u8bb8\u4e3anull,\u90a3\u5c31\u7528default\u6307\u5b9a\u4e2a\u9ed8\u8ba4\u503c\u5c31\u884c\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>gbase> alter table t1 add age int not null default -1;\r\nQuery OK, 1 row affected (Elapsed: 00:00:00.67)\r\nRecords: 1  Duplicates: 1  Warnings: 0\n\r\ngbase> alter table t1 add address varchar(100) not null default '\u672a\u77e5\u5730\u5740';\r\nQuery OK, 1 row affected (Elapsed: 00:00:00.17)\r\nRecords: 1  Duplicates: 1  Warnings: 0\r\n\r\ngbase> select * from t1 limit 10;\r\n+------+--------+-----+--------------+\r\n| id   | num    | age | address      |\r\n+------+--------+-----+--------------+\r\n|    1 | 121212 |  -1 | \u672a\u77e5\u5730\u5740     |\r\n+------+--------+-----+--------------+\r\n1 row in set (Elapsed: 00:00:00.20)\r\n\r\n<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>\u5357\u5927\u901a\u7528GBase 8a\u652f\u6301\u589e\u52a0\u65b0\u7684\u5217\uff0c\u5f53\u65b0\u589e\u5217\u6307\u5b9a\u4e86not null\u4e0d\u8bb8\u4e3anull\u65f6\uff0c\u5219\u5fc5\u987b\u6307\u5b9adefault\u9ed8\u8ba4\u503c\uff0c\u5426\u5219\u5c31\u4f1a\u62a5Column cannot be null\u6216 doesn't have a default value\u9519\u8bef\u3002<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10554","post","type-post","status-publish","format-standard","hentry","category-gbase8a"],"_links":{"self":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/10554","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/comments?post=10554"}],"version-history":[{"count":1,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/10554\/revisions"}],"predecessor-version":[{"id":10556,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/10554\/revisions\/10556"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=10554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=10554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=10554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}