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 14 views 14 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 7 Disturbing Tech Trends of 2024 December 19, 2024 AI on phones fails to impress Apple, Samsung users: Survey December 18, 2024 Standout technology products of 2024 December 16, 2024 Is Intel Equivalent to Tech Industry 2024 NY Giant? December 12, 2024 Google’s Willow chip marks breakthrough in quantum computing December 11, 2024 Job seekers are targeted in mobile phishing campaigns December 10, 2024 Leave a Comment Cancel Reply Save my name, email, and website in this browser for the next time I comment.