R
R
redduckrobot2017-07-28 11:56:39
Django
redduckrobot, 2017-07-28 11:56:39

Is it worth it to merge two tables with different ForeignKeys into one, but at the same time one of the ForeignKeys will be null?

Hello, I have something like this:

class Factory(models.Model):
    name = models.CharField(max_length=126)
    worker = models.ForeignKey(Worker, null=True)
    manager = models.ForeignKey(Manager, null=True)

Its essence lies in the fact that a Factory can have either a worker or a manager , i.e. two ForeignKeys are not used at the same time. A friend of mine recommended not to do this, because memory is also allocated for ForeignKey = null (why I didn’t understand that) and from a design point of view, this is not very good. Those. should be like this:
class FactoryWorker(models.Model):
    name = models.CharField(max_length=126)
    worker = models.ForeignKey(Worker, null=True)

class FactoryManager(models.Model):
    name = models.CharField(max_length=126)
    manager = models.ForeignKey(Manager, null=True)

I gave these models as an example and entities are not important in them. Tell me, please, in terms of performance and memory allocation (if it really happens when the value of ForeignKey = null), which is better and why?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question