I would like to know whether it is possible to create and setup my entities in my database(db) using RAW SQL in my Django Project. I understand that we can use SQL Queries to handle entities that have already been created using ORM. Examples were shown in the Django Documentation
I know that using RAW SQL is inefficient compared to using Django's ORM but one of the requirements of my project is to use SQL Statements for all database related functions.
The following is the code written in models.py in my Django app:
class Link(models.Model):
name = models.CharField(max_length=50, unique=True)
url = models.URLField(max_length=200)
slug = models.SlugField(unique=True, blank=True)
clicks = models.PositiveBigIntegerField(default=0)
The following is an example of the SQL Statements needed to create my entity:
CREATE TABLE Link (
id SERIAL PRIMARY KEY,
name VARCHAR(50) UNIQUE NOT NULL,
url VARCHAR(200) NOT NULL,
slug VARCHAR(50) UNIQUE,
clicks BIGINT DEFAULT 0
);
I can't seem to find any resources or any way to add my SQL Statements to my code using the Manager.raw(raw_query, params=(), translations=None) method.