{"id":2681,"date":"2021-02-26T10:43:48","date_gmt":"2021-02-26T01:43:48","guid":{"rendered":"https:\/\/qol-kk.com\/wp2\/?p=2681"},"modified":"2021-02-26T10:46:35","modified_gmt":"2021-02-26T01:46:35","slug":"post-2681","status":"publish","type":"post","link":"https:\/\/qol-kk.com\/wp2\/blog\/2021\/02\/26\/post-2681\/","title":{"rendered":"Django\uff1aThe Model\u540d could not be changed because the data didn't validate.\u30a8\u30e9\u30fc\u306e\u539f\u56e0\u3068\u5bfe\u7b56"},"content":{"rendered":"<h3>Django\uff1aThe Model\u540d could not be changed because the data didn't validate.\u30a8\u30e9\u30fc\u306e\u539f\u56e0\u3068\u5bfe\u7b56<\/h3>\n<p>\u3053\u308c\u306f\u79c1\u304cCRUD\u4f5c\u6210\u306e\u4e00\u756a\u6700\u521d\u306b\u82e6\u3057\u3081\u3089\u308c\u305f\u30a8\u30e9\u30fc\u3067\u3059\u3002<\/p>\n<p>POST\u3055\u308c\u305f\u5024\u306e\u30ab\u30e9\u30e0\u540d\u304cForm \/ ModelForm\u3068\u5408\u81f4\u3057\u3066\u3044\u306a\u3044\u3068\u304d\u306b\u767a\u751f\u3057\u307e\u3059\u3002<br \/>\n\u30a8\u30e9\u30fc\u767a\u751f\u539f\u306f\u69d8\u3005\u3067\u3059\u304c\u3001\u79c1\u306e\u5834\u5408\u306f\u4e0b\u306e\u7d44\u5408\u305b\u304c\u539f\u56e0\u3067\u3057\u305f\u3002<\/p>\n<div class=\"paperBox\">\n<ol>\n<li>Models.py \u5185\u3067\u3010models.DateField(null=True, default=None)\u3011\u3068\u3057\u305f\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u5bfe\u3057\u4f55\u3082\u5165\u308c\u305a\u306bPOST\u3057\u305f\u3002<\/li>\n<li>Models.py \u5185\u3067\u3010models.IntegerField(null=True, default=None)\u3011\u3068\u3057\u305f\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u5bfe\u3057\u4f55\u3082\u5165\u308c\u305a\u306bPOST\u3057\u305f\u3002<\/li>\n<li>Models.py \u5185\u3067\u3010RegexValidator(regex=r'^[0-9]+$')\u3011\u3068\u3057\u305f\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u5bfe\u3057\u4f55\u3082\u5165\u308c\u305a\u306bPOST\u3057\u305f\u3002<\/li>\n<li>POST\u3057\u305f\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30ab\u30e9\u30e0\u540d\u304cModel\u5185\u306e\u540d\u79f0\u3068\u9055\u3063\u3066\u3044\u305f<\/li>\n<\/ol>\n<\/div>\n<p>POST\u3055\u308c\u305f\u5024\u304c\u6587\u5b57\u5217\u3067\u306f\u306a\u3044\u6642\u3084\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u5f35\u3063\u3066\u3044\u308b\u30ab\u30e9\u30e0\u304c\u5b58\u5728\u3059\u308b\u6642\u3001\u3053\u306e\u30a8\u30e9\u30fc\u306e\u767a\u751f\u7387\u306f\u9ad8\u307e\u308a\u307e\u3059\u3002<\/p>\n<h3>\u306a\u306b\u3082\u8a18\u8f09\u3057\u306a\u3044\u3067POST\u3057\u305f\u5834\u5408\u3001[ \u2019\u2019 ]\u3084[ 'None' ] \u304cPOST\u3055\u308c\u3066\u3044\u308b<\/h3>\n<p>Validate\u306e\u30a8\u30e9\u30fc\u306f\u3053\u306e\u3088\u3046\u306a\u7a7a\u30c7\u30fc\u30bf\u304c\u539f\u56e0\u3068\u306a\u3063\u3066\u3044\u308b\u4e8b\u304c\u591a\u3044\u3088\u3046\u3067\u3059\u3002<br \/>\n\u56de\u907f\u3059\u308b\u624b\u6bb5\u306b\u3064\u3044\u3066\u306f<a href=\"https:\/\/qol-kk.com\/wp2\/blog\/2021\/02\/26\/post-2678\/\">\u4ee5\u524d<\/a>\u3082\u5c11\u3057\u89e6\u308c\u307e\u3057\u305f\u304c2\u3064\u3042\u308a\u307e\u3059\u3002<\/p>\n<div class=\"borderBox\">\n<ol>\n<li>Form \/ ModelForm\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u4f7f\u308f\u306a\u3044\u3002<\/li>\n<li>POST\u3055\u308c\u305f[ '' ] \u3084 [ 'None ] \u3092\u7f6e\u63db\u3057\u3066\u304b\u3089Form \/ ModelForm\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306b\u304b\u3051\u308b<\/li>\n<\/ol>\n<\/div>\n<p>\u6700\u9069\u89e3\u3068\u3057\u3066\u306f\u5916\u90e8\u95a2\u6570\u3068\u3057\u3066library.py\u306a\u3069\u306b\u4e0b\u8a18\u30b3\u30fc\u30c9\u3092\u767b\u9332\u3057\u5229\u7528\u3057\u305f\u3046\u3048\u3067\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306b\u639b\u3051\u308b\u4e8b\u3067\u3059\u3002<\/p>\n<pre class=\"lang:python decode:true\">def BlankChanger(data):\r\n    #''\u3084\u2019None\u2019\u3067POST\u3055\u308c\u305f\u5024\u3092None\u306b\u7f6e\u304d\u63db\u3048\u308b\r\n    copy_dict = data.copy()\r\n    for cd in copy_dict:\r\n        if (cd == '')or(cd == 'None'):\r\n           cd = None\r\n    return copy_dict<\/pre>\n<p>\u4e0a\u306b\u8a18\u8f09\u3057\u305f\u79c1\u304c\u7d4c\u9a13\u3057\u305f\u539f\u56e0\u306e1\uff5e3\u306f\u3053\u308c\u3067\u30af\u30ea\u30a2\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>POST\u3057\u305f\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30ab\u30e9\u30e0\u540d\u3063\u3066\u306a\u306b\uff1f<\/h3>\n<pre class=\"lang:python decode:true\">from django.db import models\r\nfrom accounts.models import CustomUser\r\n\r\nclass Customerdatas(models.Model):\r\n\r\n    customer = models.ForeignKey(CustomUser,  on_delete=models.CASCADE, verbose_name='\u30e6\u30fc\u30b6\u30fcID')\r\n    birthday = models.DateField(verbose_name=\"\u751f\u5e74\u6708\u65e5\", blank=False, auto_now=False, default=None)\r\n    lasteducation = models.CharField(verbose_name=\"\u6700\u7d42\u5b66\u6b74\", max_length=100, blank=True, null=True, default=None)\r\n    graduationdate = models.DateField(verbose_name='\u5352\u696d\u5e74\u6708', blank=True, null=True, default=None)\r\n    prmessaeg = models.TextField(verbose_name='PR\u6587', blank=True, null=True, default=None)\r\n    created_at = models.DateTimeField(verbose_name='\u4f5c\u6210\u65e5\u6642', auto_now_add=True)\r\n    updated_at = models.DateTimeField(verbose_name='\u66f4\u65b0\u65e5\u6642', auto_now=True)\r\n\r\n    class Meta:\r\n        verbose_name_plural = 'Customerdatas'\r\n\r\n        def __str__(self):\r\n            return self.CustomUser.last_name + ' ' + self.CustomUser.first_name<\/pre>\n<p>\u3053\u306e6\u884c\u76ee\u3010customer = models.ForeignKey(CustomUser, on_delete=models.CASCADE...)\u3011\u304c\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u30c6\u30fc\u30d6\u30eb\u3067\u3059\u3002\u3053\u306e\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u306f\u4eca\u300e1\u5bfe\u591a\u300f\u3067\u7d44\u3093\u3067\u3044\u307e\u3059\u3002<\/p>\n<p>\u6ce8\u76ee\u306fcustomer_id\u3067\u306f\u306a\u304fcustomer\u3067\u767b\u9332\u3057\u3066\u3044\u308b\u4e8b\u3067\u3059\u3002<\/p>\n<p>Laravel\u3067\u306fSQL\u30c6\u30fc\u30d6\u30eb\u306e\u59ff\u3092\u305d\u306e\u307e\u307e\u8a18\u8f09\u3059\u308b\u306e\u3067\u30ab\u30e9\u30e0\u306e\u547c\u3073\u51fa\u3057\u306f\u3010customer_id\u3011\u3068\u3059\u308b\u3053\u3068\u304c\u57fa\u672c\u3067\u3059\u304c\u3001Django\u306f [ _id ]\u3092\u4ed8\u3051\u308b\u4f5c\u696d\u3092\u52dd\u624b\u306b\u884c\u3063\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">customer_id = models.ForeignKey(CustomUser, on_delete=models.CASCADE, verbose_name='\u30e6\u30fc\u30b6\u30fcID')<\/pre>\n<p>\u306a\u306e\u3067\u3001\u3053\u306e\u3088\u3046\u306bmodels.py\u306b\u66f8\u3044\u305f\u5834\u5408\u3001migration\u3059\u308b\u3068MySQL\u306b\u306f\u3010customer_id_id\u3011\u3068\u3044\u3046\u30ab\u30e9\u30e0\u304c\u51fa\u6765\u4e0a\u304c\u308a\u307e\u3059\u3002<\/p>\n<h3>ModelForm\u3092\u4f7f\u3046\u5834\u5408\u3001Model\u306b\u767b\u9332\u3057\u305f\u540d\u79f0\u304c\u6b63<\/h3>\n<p>MySQL\u5185\u306e\u30ab\u30e9\u30e0\u540d\u304ccustomer_id\u306b\u306a\u3063\u3066\u3044\u3066\u3082customeruser_id\u306b\u306a\u3063\u3066\u3044\u3066\u3082\u3001Model\u306b\u5b58\u5728\u3057\u3066\u3044\u306a\u3051\u308c\u3070\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n<p>models.py\u306bcustomer \u3068\u8a18\u8f09\u3057\u3066\u3044\u308b\u306a\u3089Template.html\u3067\u306f\u3010&lt;imput name='customer' ...&gt;\u3011\u3067POST\u3057\u3066\u3042\u3052\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>\u307e\u3068\u3081<\/h3>\n<p>\u3053\u3053\u3089\u8fba\u306e\u30a8\u30e9\u30fc\u306f\u591a\u5206\u307f\u3093\u306a\u304c\u901a\u308b\u9053\u306a\u306e\u3060\u308d\u3046\u306a\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u6163\u308c\u308c\u3070\u306a\u3093\u3066\u3053\u3068\u306f\u306a\u3044\u3093\u3067\u3059\u3051\u3069\u306d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Django\uff1aThe Model\u540d could not be changed because the data didn't validate.\u30a8\u30e9\u30fc\u306e\u539f\u56e0\u3068\u5bfe\u7b56 \u3053\u308c\u306f\u79c1\u304cCRUD\u4f5c\u6210\u306e\u4e00\u756a\u6700\u521d\u306b\u82e6\u3057\u3081\u3089\u308c\u305f\u30a8\u30e9\u30fc\u3067\u3059 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2174,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"","_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[38],"tags":[943,814,99,147,97,944,53,308],"class_list":["post-2681","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-memorandum","tag-data-didnt-validate","tag-django","tag-mysql","tag-python","tag-97","tag-944","tag-53","tag-308"],"veu_head_title_object":{"title":"","add_site_title":""},"jetpack_publicize_connections":[],"jetpack-related-posts":[],"jetpack_sharing_enabled":false,"jetpack_featured_media_url":"https:\/\/qol-kk.com\/wp2\/wp-content\/uploads\/2020\/11\/django.png","_links":{"self":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts\/2681","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/comments?post=2681"}],"version-history":[{"count":0,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts\/2681\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/media\/2174"}],"wp:attachment":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/media?parent=2681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/categories?post=2681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/tags?post=2681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}