{"id":140,"date":"2013-02-20T14:42:08","date_gmt":"2013-02-20T14:42:08","guid":{"rendered":"http:\/\/demo.wpzoom.com\/seasons\/?p=140"},"modified":"2019-05-10T10:10:57","modified_gmt":"2019-05-10T10:10:57","slug":"nulla-vitae-elit-libero-a-pharetra-augue","status":"publish","type":"post","link":"http:\/\/nikeshjha.com.np\/?p=140","title":{"rendered":"Database Migration in Django"},"content":{"rendered":"<p>Standard Django installation comes loaded with SQLite database which makes it easy to get started right away with building apps as per your need. However, SQLite db is not recommended for production environment so you should consider moving to scalable database options like PostgreSQL, MySql, etc. The steps to follow when migrating from sqlite to MySql are given below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-149\" src=\"http:\/\/nikeshjha.com.np\/wp-content\/uploads\/2013\/02\/Screenshot-from-2019-01-08-10-25-02-300x91.png\" alt=\"\" width=\"300\" height=\"91\" srcset=\"http:\/\/nikeshjha.com.np\/wp-content\/uploads\/2013\/02\/Screenshot-from-2019-01-08-10-25-02-300x91.png 300w, http:\/\/nikeshjha.com.np\/wp-content\/uploads\/2013\/02\/Screenshot-from-2019-01-08-10-25-02-768x232.png 768w, http:\/\/nikeshjha.com.np\/wp-content\/uploads\/2013\/02\/Screenshot-from-2019-01-08-10-25-02-1024x309.png 1024w, http:\/\/nikeshjha.com.np\/wp-content\/uploads\/2013\/02\/Screenshot-from-2019-01-08-10-25-02-850x257.png 850w, http:\/\/nikeshjha.com.np\/wp-content\/uploads\/2013\/02\/Screenshot-from-2019-01-08-10-25-02.png 1205w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>The steps to do the database migration are given below:<\/p>\n<ul>\n<li><strong>STEP 1:<\/strong><\/li>\n<\/ul>\n<p>Dump your data to JSON file using the following command<\/p>\n<p><em><code>python\u00a0<\/code><\/em><code>manage.py dumpdata &gt; datadump.json<\/code><\/p>\n<ul>\n<li><strong>STEP 2<\/strong>:<\/li>\n<\/ul>\n<p>Change\u00a0<em>settings.py\u00a0<\/em>file to use your MySql database. You should have installed MySql for this.<\/p>\n<p><em>Sample configuration for MySql could be:<\/em><\/p>\n<pre class=\"wp-block-preformatted\">DATABASES = {\n  \u00a0'default': {\n  \u00a0\u00a0    'ENGINE': 'django.db.backends.mysql',\n  \u00a0\u00a0    'NAME': 'name_of_db',\n  \u00a0\u00a0    'USER': 'root', \u00a0\u00a0\n  \u00a0\u00a0    'PASSWORD': 'Test@123', # use the password for your MySqlDB\n  \u00a0\u00a0    'HOST': 'localhost', \u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0     'PORT': '3306'  \n}<\/pre>\n<ul>\n<li><strong>STEP 3:<\/strong><\/li>\n<\/ul>\n<p>Open the terminal and execute the following command to exclude the content type data.<\/p>\n<pre class=\"wp-block-code\"><code>from django.contrib.contenttypes.models import ContentType\nContentType.objects.all().delete()\nquit()\n<\/code><\/pre>\n<ul>\n<li><strong>STEP 4:<\/strong><\/li>\n<\/ul>\n<p><code>python manage.py loaddata datadump.json<\/code><\/p>\n<p><em>( For this thing to work you need to have mysql installed on your machine or the server you are hosting your app on )<\/em><\/p>\n<p>And you are all set. Let me know in the comments if it works for you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Standard Django installation comes loaded with SQLite database which makes it easy to get started right away with building apps as per your need. However, SQLite db is not recommended for production environment so you should consider moving to scalable database options like PostgreSQL, MySql, etc. The steps to follow when migrating from sqlite to&#8230;<\/p>\n","protected":false},"author":1,"featured_media":42,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[11,12,10,14,13],"class_list":["post-140","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-news","tag-django","tag-programming","tag-python","tag-tutorials","tag-web-development"],"_links":{"self":[{"href":"http:\/\/nikeshjha.com.np\/index.php?rest_route=\/wp\/v2\/posts\/140"}],"collection":[{"href":"http:\/\/nikeshjha.com.np\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nikeshjha.com.np\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nikeshjha.com.np\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nikeshjha.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=140"}],"version-history":[{"count":4,"href":"http:\/\/nikeshjha.com.np\/index.php?rest_route=\/wp\/v2\/posts\/140\/revisions"}],"predecessor-version":[{"id":150,"href":"http:\/\/nikeshjha.com.np\/index.php?rest_route=\/wp\/v2\/posts\/140\/revisions\/150"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/nikeshjha.com.np\/index.php?rest_route=\/"}],"wp:attachment":[{"href":"http:\/\/nikeshjha.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nikeshjha.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=140"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nikeshjha.com.np\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}