0

This is my models.py

from ast import Delete
from email.policy import default
from django.db import models
from django.contrib.auth.models import User

class Video(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    title=models.CharField(max_length=100, null=False)
    description=models.TextField(max_length=1000,null=True)
    video=models.FileField(upload_to="video/%y",null=False)

    def __str__(self):
        return self.title

class Euser(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    phone = models.CharField(max_length=10,null=True)
    birthdate = models.DateField(null=True,)
    profile_pic = models.ImageField(null=True, )
    cover_pic = models.ImageField( null=True, upload_to="images/%y")

    def __str__(self):
        return self.phone

when i try to makemigrations

It is impossible to add a non-nullable field 'id' to video without specifying a default. This is because 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 with a null value for this column)
  2. Quit and manually define a default value in models.py.

This error occurs... Please suggest me what should i do

and also suggest me about any changes in model

TRN GaBru
  • 1
  • 1
  • 1
  • if you're in your early dev stages i think u can just flush the db cause there is nothing important in the databases then retry – BGOPC Jan 29 '23 at 14:04

2 Answers2

2

For a particular model, in the database, if records already exist and add new fields to the model then it shows such an error. To overcome this problem, you have to set the new field as blank=True and null=True or you can set some default value to the new field using default='some_value'.

Manoj Kamble
  • 620
  • 1
  • 4
  • 21
0

@Manoj Kamble, i was trying 'default' and it was not working (I already had DB filled with attributes)...blank=True, null=True worked for me! Thanks

  • Please don't add "thank you" as an answer. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation), you will be able to [vote up questions and answers](https://stackoverflow.com/help/privileges/vote-up) that you found helpful. - [From Review](/review/late-answers/34665901) – Alez Jul 12 '23 at 12:24