0
votes

Student programmer here! so go easy...

My team and I are building a web app with Django that centres around creating a structured database, inserting data that has been extracted from PDF's, and enabling users to view records in the database. Its for an archeology department for their paper based archive that needs to be digitized.

First time Django and Azure user, so I don't fully understand how/if they fit together.

I've begun coding the models.py file to create the models. Do we also need to set up Azure SQL to store the db? Or is it completely managed by Django, seeing as it has its on backend interface? Basically, is ORM just used to initialise the database and for accessing the objects, but something still needs to be set up on Azure specifically for the database?

Thanks in advance

1
Database (in this case Azure SQL) is a separate resource which your web framework (here Django) access to store data. Models.py file is kind of a bridge between the Database and django. You can access the database even without creating a models.py file in your project but django gives you the functionailty of models.py to interact with the Database in an easy manner. Answering your actual question: Yes, you need to create an Azure SQL database instance separately.Chayan Bansal

1 Answers

0
votes

To make your web application communicate to the data, yes you need to create Azure SQL Database and use the database administrator account details in settings.py to connect your Web Application with your database and perform CRUD operations.

You can create SQL Server in azure and then create a database inside it. Please follow below steps to create SQL Server using Azure Portal.

Search for "sql server" on top search box and select SQL servers.

enter image description here

Click on + Create to create a new SQL Server.

Select Subscription and Resource Group, fill Server name, Location and Administrator account and then click on Review + create as shown below. Go to the resource once it is deployed.

enter image description here

Do not forget to Allow azure service and resources to access this server in Firewall and virtual networks under Security for SQL Server. enter image description here

Create Database in your SQL server.

enter image description here

Give the database name and you can keep all other options as default. Click on create and review and then create the DB. enter image description here

Once your DB is deployed. You need to whitelist the IP to run SQL query on this DB. Go to the query editor in your Database and provide your password. Click on the appearing message to whitelist the IP.

enter image description here

To connect the database with your Django framework, the simple way is that follow the django-pyodbc-azure README to install python packages pyodbc & django-pyodbc-azure and configure the settings.py file of Django correctly as below.

DATABASES = {
     'default': {
         'ENGINE': 'sql_server.pyodbc',
         'NAME': '<DatabaseName>',
         'USER': '<UserName>',
         'PASSWORD': '{your_password_here}',
         'HOST': '<ServerName>',
         'PORT': '<ServerPort>',
         'OPTIONS': {
             'driver': 'ODBC Driver 13 for SQL Server',
             'MARS_Connection': 'True',
         }
     }
 }