I have two models with the same field. When I try to add a new instance to my database, one throws the error in the title, the other does not.
models.py
class Housesit(BaseModel):
user = models.ForeignKey(CustomUser, on_delete=models.DO_NOTHING)
home = models.ForeignKey(Home, on_delete=models.DO_NOTHING)
title = models.CharField(max_length=256)
<more fields>
def __str__(self):
return self.title
class ShortTermRental(BaseModel):
user = models.ForeignKey(CustomUser, on_delete=models.DO_NOTHING)
home = models.ForeignKey(Home, on_delete=models.DO_NOTHING)
title = models.CharField(max_length=256)
<more fields>
views.py
def add_housesit(request):
active_user = request.user
if not active_user.is_authenticated:
return warn_redirect_login(request)
new_housesit = Housesit.objects.create(user=active_user)
return redirect("update_housesit", pk=new_housesit.id)
def add_short_term_rental(request):
active_user = request.user
if not active_user.is_authenticated:
return warn_redirect_login(request)
new_short_term_rental = ShortTermRental.objects.create(user=active_user)
return redirect("update_short_term_rental", pk=new_short_term_rental.id)
urls.py
urlpatterns = (
[
path("housesit/add/", views.add_housesit, name="add_housesit"),
path(
"short_term_rental/add/",
views.add_short_term_rental,
name="add_short_term_rental",
),
]
I can’t for the life of me figure out what’s different between them and why one throws an error and the other doesn’t. I’m fully migrated. Where else could the source of the discrepency possibly be? A simple solution would be to simply add “null=True” to my Home field, but I’m trying to figure out why it’s broken. Any insight greatly appreciated!