0

I've attempted to add a second ForeignKey relationship to a Django Model which relates to a model which hasn't yet been created.

class Forms2012(models.Model): """ Employer forms for the 2012-13 tax year """ employer = models.ForeignKey('Employer', blank=True, null=True) # employee model is yet to be implemented employee = models.ForeignKey('Employee', blank=True, null=True) name = models.CharField( max_length=50, choices=constants.FORM_CHOICES) description = models.CharField(max_length=255) datemodified = models.DateTimeField() 

As you might expect this is giving a not installed or is abstract error. However I've been told it should be possible to validate this because that key is optional.

Could someone explain if this is possible, I've added the flags blank=True, null=True to the FK but model validation fails so I think I'm fighting a losing battle.

2 Answers 2

1

Why don't you make (temporary) dummy models?

Sign up to request clarification or add additional context in comments.

2 Comments

Thats what I wanted to do but was advised otherwise. I wasn't sure if there was something I'd missed as I've not been working with Django for very long.
I wouldn't know why not to do this. Even if you don't use South it is easy enough to drop the dummy table and do a syncdb when you have the actual model done.
0

I would recommend that you implement a "stub" Employee model eg

class Employee(models.Model): pass 

If you are using database migrations ( eg South ), which you should, it should be a simple matter to "fill out" the Employee class later on.

However, if you want a fairly involved "solution" to the problem, you can have a look at the accepted answer in this question. The author of the question & answer admits that it is ugly ( even though it works ). The "stub" solution is better.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.