{"id":5276,"date":"2024-12-18T23:29:40","date_gmt":"2024-12-18T14:29:40","guid":{"rendered":"https:\/\/417.run\/?p=5276"},"modified":"2024-12-18T23:29:40","modified_gmt":"2024-12-18T14:29:40","slug":"reset-db","status":"publish","type":"post","link":"https:\/\/417.run\/pg\/python\/django\/reset-db\/","title":{"rendered":"Django\u3067DB\u3092\u6d88\u3057\u3066\u3084\u308a\u76f4\u3057\u305f\u3044\u3068\u304d\u306e\u3084\u308a\u65b9"},"content":{"rendered":"<p>DB\u306e\u8a2d\u8a08\u3092\u3092\u8003\u3048\u3066\u308b\u6bb5\u968e\u3067\u3001\u3084\u308a\u76f4\u3057\u305f\u304f\u306a\u3063\u305f\u6642\u306b\u3001<br \/>\n\u30a2\u30d7\u30ea\u5358\u4f4d\u3067\u5168\u90e8\u6d88\u3059\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n<p>\u307e\u305a\u3053\u3093\u306a\u304b\u3093\u3058\u3001\u3067\u304d\u308b\u3068\u805e\u3044\u305f\u3093\u3067\u3059\u304c\u3001\u3053\u308c\u304c\u30a8\u30e9\u30fc\u306b\u306a\u3063\u305f\u306e\u3067\u3001<br \/>\n\u3053\u308c\u304c\u3067\u304d\u306a\u304b\u3063\u305f\u4eba\u5411\u3051\u306b\u8a71\u3092\u9032\u3081\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-sh\">python manage.py migrate app_name zero<\/code><\/pre>\n<p>\u203b<code>app_name<\/code>\u306f\u30a2\u30d7\u30ea\u540d\u306b\u5909\u66f4<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_17 counter-hierarchy counter-decimal ez-toc-grey\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\">\u76ee\u6b21<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<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:\/\/417.run\/pg\/python\/django\/reset-db\/#1_%E3%83%9E%E3%82%A4%E3%82%B0%E3%83%AC%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%81%AE%E3%83%AD%E3%82%B0%E3%82%92%E6%B6%88%E3%81%99\" title=\"1. \u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u30ed\u30b0\u3092\u6d88\u3059\">1. \u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u30ed\u30b0\u3092\u6d88\u3059<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/417.run\/pg\/python\/django\/reset-db\/#2_%E3%83%9E%E3%82%A4%E3%82%B0%E3%83%AC%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%82%92%E6%B6%88%E3%81%99\" title=\"2. \u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u3092\u6d88\u3059\">2. \u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u3092\u6d88\u3059<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/417.run\/pg\/python\/django\/reset-db\/#3_drop%E3%81%99%E3%82%8B\" title=\"3. drop\u3059\u308b\">3. drop\u3059\u308b<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/417.run\/pg\/python\/django\/reset-db\/#4%E6%96%B0%E3%81%97%E3%81%8F%E4%BD%9C%E3%82%8B\" title=\"4.\u65b0\u3057\u304f\u4f5c\u308b\">4.\u65b0\u3057\u304f\u4f5c\u308b<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"1_%E3%83%9E%E3%82%A4%E3%82%B0%E3%83%AC%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%81%AE%E3%83%AD%E3%82%B0%E3%82%92%E6%B6%88%E3%81%99\"><\/span>1. \u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u30ed\u30b0\u3092\u6d88\u3059<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u3068\u308a\u3042\u3048\u305a\u3001<code>--fake<\/code>\u3092\u3064\u3051\u3066\u5b9f\u884c\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3<\/p>\n<pre><code class=\"language-sh\">python manage.py migrate --fake app_name zero<\/code><\/pre>\n<p>\u203b<code>app_name<\/code>\u306f\u30a2\u30d7\u30ea\u540d\u306b\u5909\u66f4<br \/>\n\u3053\u308c\u3067\u4e00\u5fdc\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u30ed\u30b0\u3068\u304b\u304c\u6d88\u3048\u307e\u3059\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"2_%E3%83%9E%E3%82%A4%E3%82%B0%E3%83%AC%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%82%92%E6%B6%88%E3%81%99\"><\/span>2. \u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u3092\u6d88\u3059<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre><code class=\"language-sh\">rm app_name\/migrations\/0*.py<\/code><\/pre>\n<p>\u203b<code>app_name<\/code>\u306f\u30a2\u30d7\u30ea\u540d\u306b\u5909\u66f4<\/p>\n<h2><span class=\"ez-toc-section\" id=\"3_drop%E3%81%99%E3%82%8B\"><\/span>3. drop\u3059\u308b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u3042\u3068\u306f\u3001\u3064\u304f\u3063\u305f\u30c6\u30fc\u30d6\u30eb\u30c9\u30ed\u30c3\u30d7\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"4%E6%96%B0%E3%81%97%E3%81%8F%E4%BD%9C%E3%82%8B\"><\/span>4.\u65b0\u3057\u304f\u4f5c\u308b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u5f8c\u306f\u3044\u3064\u3082\u901a\u308a\u4f5c\u308a\u76f4\u3059<\/p>\n<pre><code class=\"language-sh\">python manage.py makemigrations\npython manage.py migrate<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>DB\u306e\u8a2d\u8a08\u3092\u3092\u8003\u3048\u3066\u308b\u6bb5\u968e\u3067\u3001\u3084\u308a\u76f4\u3057\u305f\u304f\u306a\u3063\u305f\u6642\u306b\u3001 \u30a2\u30d7\u30ea\u5358\u4f4d\u3067\u5168\u90e8\u6d88\u3059\u65b9\u6cd5\u3067\u3059\u3002 \u307e\u305a\u3053\u3093\u306a\u304b\u3093\u3058\u3001\u3067\u304d\u308b\u3068\u805e\u3044\u305f\u3093\u3067\u3059\u304c\u3001\u3053\u308c\u304c\u30a8\u30e9\u30fc\u306b\u306a\u3063\u305f\u306e\u3067\u3001 \u3053\u308c\u304c\u3067\u304d\u306a\u304b\u3063\u305f\u4eba\u5411\u3051\u306b\u8a71\u3092\u9032\u3081\u307e\u3059\u3002 python man &#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[67],"tags":[],"class_list":{"0":"post-5276","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-django","7":"nothumb"},"_links":{"self":[{"href":"https:\/\/417.run\/wp-json\/wp\/v2\/posts\/5276"}],"collection":[{"href":"https:\/\/417.run\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/417.run\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/417.run\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/417.run\/wp-json\/wp\/v2\/comments?post=5276"}],"version-history":[{"count":1,"href":"https:\/\/417.run\/wp-json\/wp\/v2\/posts\/5276\/revisions"}],"predecessor-version":[{"id":5277,"href":"https:\/\/417.run\/wp-json\/wp\/v2\/posts\/5276\/revisions\/5277"}],"wp:attachment":[{"href":"https:\/\/417.run\/wp-json\/wp\/v2\/media?parent=5276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/417.run\/wp-json\/wp\/v2\/categories?post=5276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/417.run\/wp-json\/wp\/v2\/tags?post=5276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}