我正在嘗試爲網站設計一個數據庫結構,該網站提供人們打開個人資料。 我想弄清楚我選擇的設計是否足夠好。我懷疑它可能有問題的原因是我使用很多表之間的許多關係。這樣,當一個人的頁面被加載時,幕後會有很多JOIN,這肯定會造成一個瓶頸。如果您能幫我弄清楚設計是否合適或者我應該重新考慮它,我將不勝感激。用Django設計數據庫結構
於是我想出了以下設計:
class Person(models.Model):
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)
name = models.CharField(max_length=200)
# Each person can have one profession
profession = models.ForeignKey(Profession)
email = models.CharField(max_length=100, blank=True)
website = models.CharField(max_length=200, blank=True)
gender = models.CharField(max_length=1, choices=GENDER_CHOICES))
birth_date = models.DateField(blank=True, null=True)
class Profession(models.Model):
type = models.CharField(max_length=20, blank=False, choices = ("Teacher","Pilot","Politician"))
#Each person can have several geolocations (represent the person's home/office/other address)
class Geolocation(models.Model):
latitude = models.FloatField()
longitude = models.FloatField()
address = models.TextField()
related_person = models.ForeignKey(Person, blank=False, null=False)
#Each person can have several medias (you tube movies)
class Media(models.Model):
youtube_id = models.CharField(max_length=100)
related_person = models.ForeignKey(Person, blank=False, null=False)
#Each person can have several websites
class Websites(models.Model):
website_url = models.CharField(max_length=200, blank=False)
website_name = models.CharField(max_length=200)
related_person = models.ForeignKey(Person, blank=False, null=False)
#See below...
related_link_farm = models.ForeignKey(LinkFarms, blank=True, null=True)
#Each website that refers to a person must be also refered to a link farm
class LinkFarms(models.Model):
farm_name = models.CharField(max_length=200, blank=False)
注意,每個頁面加載至少有5臺連接。
感謝,
梅厄