I thought I would work a little on my game with Django, developing a large-scale business application for fun. I saw the need for a common ancestor approach to modeling inheritance and tried to implement it based on official documentation. However, I keep getting this very annoying message, which I'm not sure what to do.
- Dj Version: Django 1.7
- Py Version: Python 3.4.2
Message
$ python manage.py makemigrations
You are trying to add a non-nullable field 'businessentity_ptr' to business without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows)
2) Quit, and let me add a default in models.py
Models.py
class BusinessEntity(models.Model):
title = models.CharField(max_length=180)
def __str__(self):
return self.title
class Business(BusinessEntity):
description = models.TextField(max_length=600)
claimed = models.BooleanField(default=False)
slug = models.SlugField()
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
updated = models.DateTimeField(auto_now_add=False, auto_now=True)
def __str__(self):
return self.description
What I tried (which everyone will hate):
- Database deletion and re-migration
- setting default value for all fields
- Setting all fields to
null = True
, , . , -, Django Common Ancestors .