一、定义:
from django.db import models # Create your models here. class Person(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100) class Meta():
index_together = ["first_name", "last_name"]
二、生成目标SQL:
python3 manage.py makemigrations polls
Migrations for 'polls':
polls/migrations/0001_initial.py
- Create model Person
- Alter index_together for person (1 constraint(s))
三、查看目标SQL:
python3 manage.py sqlmigrate polls 0001
BEGIN;
--
-- Create model Person
--
CREATE TABLE "polls_person" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "first_name" varchar(100) NOT NULL, "last_name" varchar(100) NOT NULL);
--
-- Alter index_together for person (1 constraint(s))
--
CREATE INDEX "polls_person_first_name_last_name_0c87f2f4_idx" ON "polls_person" ("first_name", "last_name");
COMMIT;