shashank shashank - 5 months ago 32
Python Question

You are trying to add a non-nullable field 'id' to contact_info without a default

i am just using simple command python makemigrations

However, all I get is this error:

You are trying to add a non-nullable field 'id' to contact_info 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

Here is

class Document(models.Model):
docfile = models.FileField(upload_to='documents/')

class contact_number(models.Model):
contact_numbers= models.CharField(max_length=13)

class contact_address(models.Model):
address = models.CharField(max_length=100)
city = models.CharField(max_length=50)
state = models.CharField(max_length=50)
zip = models.CharField(max_length=5)

class contact_info(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
email = models.EmailField()


you could set `default="" and also editable=False.

E.g first_name = models.CharField(max_length=50, default="", editable=False).

Adding id field is unnecessary. Django will add it automatically.

Edit: Deleting the last migration files in your migrations folder and retry again. If it doesn't work, repeat the same process, you will know you have deleted the right file when your "makemigrations" command works.