Integrating Azure SQL with Django : A Step-by-Step Guide by info.odysseyx@gmail.com September 27, 2024 written by info.odysseyx@gmail.com September 27, 2024 0 comment 2 views 2 hi👋 My name is Sourabh and I am a student ambassador from Bangalore studying Computer Science at BIT. Azure SQL and Django integration Migrate your Django project to a cloud-based database such as Azure SQL It can significantly improve scalability, reliability, and performance. This guide walks you through integrating Django with Azure SQL. prerequisites 1. Azure subscription: get Azure for students You can receive $100 in credit over 12 months.2. Django project: Make sure you have an existing Django project set up.3. VS Code: install visual studio code Code editing to suit your needs. Required Package pip install django pyodbc mssql-django Install ODBC DriverTo connect Django to Azure SQL, you need to install the ODBC driver for SQL Server. The following command installs ODBC Driver 17 for SQL Server depending on your operating system. For Ubuntu/Linux: sudo su curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list exit sudo apt-get update sudo ACCEPT_EULA=Y apt-get install -y msodbcsql17 sudo apt-get install -y unixodbc-dev For macOS: brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release brew update brew install --no-sandbox msodbcsql17 mssql-tools For Windows:You can download and install the driver from: Microsoft’s website. Once the drivers are installed, your Django project should be able to connect to Azure SQL using: mssql-django Package. Why use Azure SQL instead of SQLite3? Scalability: Easily handle large data sets and high traffic. Trustworthy: Managed by Microsoft and provides high availability and disaster recovery capabilities. security: Advanced features like encryption, threat detection, and compliance. Performance: Features like automatic tuning and intelligent query processing. Remote access: Access your database from anywhere. Step-by-step integration 1. Set up Azure SQL Database Deployment options for Azure SQLNote – Deployment can also be done through the Azure portal. Create a resource group. az group create -l -n ​ Create SQL Server: az sql server create -n -l --admin-user --admin-password -g ​ Create a database: az sql db create -g -s -n my-db --service-objective GP_Gen5_2​ Allow the IP in your firewall: az sql server firewall-rule create --resource-group --server --name AllowMyClientIP --start-ip-address --end-ip-address ​ 2. Install required packages pip install django pyodbc mssql-django 3. Configure Django Settings in settings.pyupdate database part time job: DATABASES = { 'default': { 'ENGINE': 'mssql', 'NAME': 'my-db', 'USER': '', 'PASSWORD': '', 'HOST': '.database.windows.net', 'PORT': '', 'OPTIONS': { 'driver': 'ODBC Driver 17 for SQL Server', }, } } 4. Migration and Migration python manage.py makemigrations python manage.py migrate 5. Run the server python manage.py runserver And that’s it! Your Django project is now integrated with Azure SQL :party_popper:. Additional resources:– Azure SQL documentation– mssql-django GitHub repository Happy coding! Useful Links1. Create a REST API using Python, Django, and Azure SQL2. Create a REST API in Python using Django and Azure SQL3. Deploy Python (Django/Flask) apps using PostgreSQL on Azure4. Azure SQL migration using Data Studio5. Azure SQL Django samples on GitHub Source link Share 0 FacebookTwitterPinterestEmail info.odysseyx@gmail.com previous post Exciting Job Opening: Business Exhibition Research and Lead Generation Specialist at Talent Corner HR Services in Mumbai next post Exciting Business Development Executive Opportunities at Intouch Quality Services in Delhi You may also like From Zero to Hero: Building Your First Voice Bot with GPT-4o Real-Time API using... October 12, 2024 A Guide to Responsible Synthetic Data Creation October 12, 2024 Capacity Template – MGDC for SharePoint October 11, 2024 Using Azure NetApp Files (ANF) for data- and logfiles for Microsoft SQL Server in... October 11, 2024 Microsoft Community – Do you love stickers?! Do you want to be a part... October 11, 2024 Advanced Alerting Strategies for Azure Monitoring October 11, 2024 Leave a Comment Cancel Reply Save my name, email, and website in this browser for the next time I comment.