Tuesday, May 28, 2019

Re: What's wrong with this model

By default CharField is not Nullable meaning it can't be created with out some data in it. 

You have two options:
Make field nullable:  blank=True
Or add a default: default=default_text

On Monday, May 27, 2019 at 4:52:19 PM UTC-5, Saeed Pooladzadeh wrote:
Hello

I made this model and think everything is fine:

class Smodel(models.Model):

    eid=models.AutoField(primary_key=True)
   # eid=models.IntegerField(default=0)
    elogin = models.CharField(max_length=8) 
    epassword= models.CharField(max_length=8) 
  
    elikeDay=models.IntegerField(default=0)
    efollowPerDay=models.IntegerField(default=0)
    

   
    #esession = models.TextField()
    class Meta:  
        db_table = "saeed"  


  'But when I try to 'make migration 
I get this error:

You are trying to add a non-nullable field 'elogin' to smodel 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 with a null value for this column)
 2) Quit, and let me add a default in models.py
Select an option: 


What is wrong with this model and how can I resolve it?

regards,
Saeed 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ceb076de-7592-4de1-9732-64bd5c0031dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment