class Organization(models.Model):
mLeader = models.ForeignKey(User)
mName = models.CharField(max_length=30, default='-')
mTel = models.CharField(max_length=15, default='-')
mAddress = models.TextField(default='-')
mType = models.CharField(max_length=1, default='A') # A : Daycare Center, B : private educational institute, C : Church, D : ...
owner = models.ForeignKey('auth.User', related_name='Organization')
def __str__(self) :
return self.mName
class OrganizationLeader(models.Model):
#private info
mUser = models.ForeignKey(User)
owner = models.ForeignKey('auth.User', related_name='Leader')
# mName = models.CharField(max_length=30, default='-')
class BusLine(models.Model):
mOrganization = models.ForeignKey(Organization)
mName = models.CharField(max_length=30, default='-')
mIsPrivate = models.BooleanField(default=True)
mCreated = models.DateTimeField(auto_now_add=True)
mIsCycle = models.BooleanField(default=False)
owner = models.ForeignKey('auth.User', related_name='lines')
class Meta:
ordering = ('mCreated', )
class BusStation(models.Model):
mName = models.CharField(max_length=30, default='-')
mCreated = models.DateTimeField(auto_now_add=True)
mOrder = models.IntegerField(default=None)
mIsStart = models.BooleanField(default=False)
mIsEnd = models.BooleanField(default=False)
mBusLine = models.ManyToManyField('BusLine', blank=True, null=True)
#변수명이 고정돼있어 접미사 붙이지 않음
mpoint = models.PointField(default=None)
objects = models.GeoManager()
Latitude = models.DecimalField(default=0.0, max_digits=10, decimal_places=6)
Longitude = models.DecimalField(default=0.0, max_digits=10, decimal_places=6)
owner = models.ForeignKey('auth.User', related_name='stations')
class Meta:
ordering = ['mOrder']
class Bus(models.Model):
mDriver = models.ForeignKey(User)
mDriving = models.BooleanField(default=False)
mCurrentStation = models.IntegerField(default=0)
mCreated = models.DateTimeField(auto_now_add=True)
mName = models.CharField(max_length=100)
mBusLine = models.ForeignKey('BusLine', on_delete=models.CASCADE, blank=True, null=True)
mArrive = models.BooleanField(default=False)
#LSB Data
#변수명이 고정돼있어 접미사 붙이지 않음
mpoint = models.PointField(default=None)
objects = models.GeoManager()
Latitude = models.DecimalField(default=0.0, max_digits=10, decimal_places=6)
Longitude = models.DecimalField(default=0.0, max_digits=10, decimal_places=6)
owner = models.ForeignKey('auth.User', related_name='buses')
def save(self, *args, **kwargs):
self.Latitude = self.mpoint.y
self.Longitude = self.mpoint.x
super(Bus, self).save(*args, **kwargs)
class Meta:
ordering = ('mCreated', )
class PassengerLogManager(models.Manager):
def create_log(self, id):
log = self.create(mBusId = id)
return log
class PassengerLog(models.Model):
mBusId = models.IntegerField()
mCreated = models.DateTimeField(auto_now_add=True,)
#JSON 필드에 버스의 한 회차 정류장당 탑승자 리스트가 저장됨
mLog = JSONField()
objects = PassengerLogManager()
class AppUser(models.Model):
#private info
mUser = models.ForeignKey(User)
mBaseDestination = models.ForeignKey(
BusStation,
verbose_name = 'BaseDestination',
default = '-',
)
mName = models.CharField(
verbose_name = 'UserName',
max_length=30,
blank = False,
default = '-'
)
mChild = models.ManyToManyField(
'self',
through = 'ParentToChildEntry',
verbose_name = 'Child',
through_fields = ('mParent','mChild'),
symmetrical = False,
)
owner = models.ForeignKey('auth.User', related_name='User')
def __str__(self) :
return self.mName
class ParentToChildEntry(models.Model) :
mName = models.CharField(
max_length = 20,
verbose_name = 'Title',
blank = False,
default = '-'
)
mParent = models.ForeignKey(
AppUser,
verbose_name = 'Parent',
related_name = 'Parent',
)
mChild = models.ManyToManyField(
AppUser,
verbose_name = 'Child',
related_name = 'Child',
)
def __str__(self) :
return self.mName
class OrganizationToUserEntry(models.Model) :
mName = models.CharField(
max_length = 20,
verbose_name = 'Title',
blank = False,
default ='-'
)
mOrganizations = models.ForeignKey(
Organization,
verbose_name = 'Organization'
)
mUsers = models.ManyToManyField(
AppUser,
verbose_name = 'Users'
)
def __str__(self) :
return self.mName
上面的代码是一个总线管理系统模型。(Django版本1.11.4) 首先,当我尝试在管理员中启动并测试时,
错误(1054,“字段列表'中的未知列'DataMng_appuser.mBaseDestination_id'”)
引起了轰动,所以我刷了DB并迁移了模型 但是,当我尝试迁移此模型时,系统返回了我
[警告:DataMng.BusStation.mBusLine:(fields.W340)null对ManyToManyField没有影响。]
我反复找到了如何解决这个问题,但我找不到。 请告诉我应该做什么T_T。谢谢你的阅读。