Django说我迁移时没有任何变化

时间:2016-10-19 14:51:40

标签: python django migration

我试图为一所虚构的学校创建一个数据库。当我尝试迁移表时,会发生这种情况:

C:\ Python34 \ Scripts \ schoolDatabase> manage.py makemigrations school

C:\ Python34 \ Scripts \ schoolDatabase> python manage.py makemigrations school 在app' school'

中未检测到任何更改

这是我所说的模型:

TYPE_OF_PERSON = (
('T', 'Teacher'),
('S', 'Student'),) 
DETENTION_COMPLETED = (
('Y', 'Yes'),
'N', 'No'
OUTCOME = (
('P', 'Pass'),
('F', 'Fail')
)
class Person:
first_name = models.CharField(max_length = 25)
surname = models.CharField(max_length = 25)
address = models.CharField(max_length = 45)
year_group = models.CharField(max_length = 10)
form = models.CharField(max_length = 15)
type_of_person = models.CharField(choices = TYPE_OF_PERSON)
person_id = models.CharField(primary_key = True)

class Subject:
name = models.CharField(max_length = 25)
class SchoolClass:
class_id = models.IntegerField(primary_key = True)
person_id = models.ForeignKey('Person')
subject = models.ForeignKey('Subject')
year_group = models.ForeignKey('Person')

class Attendance:
school_class = models.ForeignKey('SchoolClass')
date = models.DateField()
start_time = models.TimeField()
end_time = models.TimeField()
person_id = models.ForeignKey('Person')

class Assignment:
assignment_id = models.IntegerField(primary_key = True)
subject = models.ForeignKey('Subject')
school_class = models.ForeignKey('SchoolClass')
teacher = models.ForeignKey('Person')
description =models.TextField()
date_set = models.DateField()
due_date = models.DateField()
mark = models.CharField(max_length = 20)
comments = models.TextField()

class Detention:
detention_date = models.DateField()
student_id = models.ForeignKey('Person')
reason = models.CharField(max_length = 30)
completed = models.CharField(choices = DETENTION_COMPLETED)

class Exam:
exam_id = models.IntegerField(primary_key = True)
subject = models.ForeignKey('Subject')
paper = models.CharField(max_length = 30)
score = models.CharField(max_length = 20)
outcome = models.CharField(choices = OUTCOME)

我听说如果托管设置为False,那么Django在迁移时不会创建表格,但我不知道如何将其设置为True。

当我输入时:

manage.py inspectdb它向我显示托管设置为False,但是如何将其更改为True以便迁移我的数据库?

这是追溯:

C:\ Python34 \ Scripts \ schoolDatabase> manage.py makemigrations school

C:\ Python34 \ Scripts \ schoolDatabase> python manage.py makemigrations school 在app' school'

中未检测到任何更改
                                                                                                                          class DjangoMigrations(models.Model):                              id = models.IntegerField(primary_key=True)  # AutoField?       app = models.CharField(max_length=255)                         name = models.CharField(max_length=255)                        applied = models.DateTimeField()                                                                                              class Meta:                                                        managed = False                                                db_table = 'django_migrations'                         

这是树:

enter image description here enter image description here

很抱歉格式不佳但是stackoverflow不会让我把它放在代码块中。

任何帮助将不胜感激。

Settings.py:

INSTALLED_APPS =[
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages.',
'django.contribe.staticfiles',
'school'
]

1 个答案:

答案 0 :(得分:0)

你的模型应该来自models.Model:

 class Person(models.Model):
 ...
 class Subject(models.Model):
 ...
 ...