Open
Description
I am getting the following error when I am setting a function as a default
value for a foreign key. I have the decorator on many tests, but it doesn't even finish loading the first test with the decorator before exploding.
Failed: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.
Here is what I have:
class Score(models.Model):
def default_value():
return Sport.objects.get(game='football').id
sport = models.ForeignKey(
Sport,
null=True,
blank=True,
on_delete=models.SET_NULL,
default=default_value
)
- This works with django since default is either looking for a value or a callable.
- It works in migrations since it is being called after all of the apps are initialized.
- It also just works in the normal course of using the project
I suspect this is just tripping up the order of something getting loaded.