django - Constraints when writing Python class -
i`m using python 3.5.2 , django 1.11 using sqlite
i faced situation want name model class name, different names different results in manage.py migration regarding foreignkeys
example shell:
modules.py
from django.db import models class place(models.model): question_text = models.charfield(max_length=200) class choice(models.model): question = models.foreignkey(place, on_delete=models.cascade)
running python3 manage.py makemigrations post
migrations 'post': post/migrations/0001_initial.py - create model choice - create model place - add field question choice'
when renaming class choice in example "rating":
from django.db import models class place(models.model): question_text = models.charfield(max_length=200) class rating(models.model): question = models.foreignkey(place, on_delete=models.cascade)
output of migration attempt:
migrations 'post': post/migrations/0001_initial.py - create model place - create model rating
you might notice foreign key implementation disappeared. i`ve triple checked everywhere. tried new projects. stuck few days. there class naming restrictions or sort of bug?
have nice holidays, thanks.
it's not bug, in both cases foreign key created.
in first case, choice
model created first, , since place
doesn't exist yet, can't create foreign key @ time model created. therefore added later in separate step after place
model created.
in second case, place
model created first, foreign key can created in createmodel
operation rating
.
ideally, both cases produce second output whenever possible, contains less steps, optimisation hasn't been implemented yet.
Comments
Post a Comment