{"id":175,"date":"2025-05-14T06:05:32","date_gmt":"2025-05-14T06:05:32","guid":{"rendered":"https:\/\/kingstatue.com\/?p=175"},"modified":"2025-05-14T06:05:32","modified_gmt":"2025-05-14T06:05:32","slug":"how-to-use-ms-sql-server-with-django-on-windows","status":"publish","type":"post","link":"https:\/\/www.kingstatue.com\/?p=175","title":{"rendered":"How To Use MS SQL Server with Django on Windows"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">To use MS <strong>SQL Server<\/strong> as the database for your <strong>Django application<\/strong>, follow these steps:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. <strong>Install Required Packages<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Django does not support SQL Server out of the box, so you need a third-party database backend:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After setting up and activating virtual environment, install Django, then install mssql-django<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install mssql-django\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. <strong>Update <code>DATABASES<\/code> in <code>settings.py<\/code><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open your Django project\u2019s <code>settings.py<\/code> and configure the <code>DATABASES<\/code> setting:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DATABASES = {\n    'default': {\n        'ENGINE': 'mssql',\n        'NAME': 'your_db_name',\n        'USER': 'your_db_user',\n        'PASSWORD': 'your_db_password',\n        'HOST': 'your_db_host',       # For local: 'localhost' or '127.0.0.1'\n        'PORT': '1433',               # Default SQL Server port\n        'OPTIONS': {\n            'driver': 'ODBC Driver 17 for SQL Server',  # Or 'ODBC Driver 18 for SQL Server' if installed\n        },\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>Install ODBC Driver<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Depending on your operating system, install the appropriate <strong>ODBC driver<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Windows<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Install from: <a class=\"\" href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/connect\/odbc\/download-odbc-driver-for-sql-server\">https:\/\/learn.microsoft.com\/en-us\/sql\/connect\/odbc\/download-odbc-driver-for-sql-server<\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Ubuntu\/Linux<\/strong>:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo su\ncurl https:\/\/packages.microsoft.com\/keys\/microsoft.asc | apt-key add -\ncurl https:\/\/packages.microsoft.com\/config\/ubuntu\/20.04\/prod.list > \/etc\/apt\/sources.list.d\/mssql-release.list\nexit\nsudo apt-get update\nsudo ACCEPT_EULA=Y apt-get install -y msodbcsql17<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>Run Migrations<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">After updating your database settings:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python manage.py makemigrations\npython manage.py migrate<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To use MS SQL Server as the database for your Django application, follow these steps: 1. Install Required Packages Django does not support SQL Server out of the box, so&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,5],"tags":[48,57,58,73],"class_list":["post-175","post","type-post","status-publish","format-standard","hentry","category-django","category-ms-sql-server-database","tag-django","tag-ms-sql-server","tag-mssql","tag-sql-server"],"_links":{"self":[{"href":"https:\/\/www.kingstatue.com\/index.php?rest_route=\/wp\/v2\/posts\/175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kingstatue.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kingstatue.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kingstatue.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kingstatue.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=175"}],"version-history":[{"count":0,"href":"https:\/\/www.kingstatue.com\/index.php?rest_route=\/wp\/v2\/posts\/175\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kingstatue.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kingstatue.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kingstatue.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}