What's wrong with this model

26 views
Skip to first unread message

Saeed Pooladzadeh

unread,
May 27, 2019, 5:52:19 PM5/27/19
to Django users
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 

Gil Obradors

unread,
May 27, 2019, 6:00:15 PM5/27/19
to django...@googlegroups.com
Yes, your are adding new field elogin.
Table contains data
You must specify a default on all existing rows, selecting 1 and writing to console something










Missatge de Saeed Pooladzadeh <ling...@gmail.com> del dia dl., 27 de maig 2019 a les 23:52:
--
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...@googlegroups.com.
To post to this group, send email to django...@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/dee2a6de-49e9-45c4-8536-0bed15038bd9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chandrashekhar Singh

unread,
May 27, 2019, 6:01:33 PM5/27/19
to django...@googlegroups.com
You have to add null= true to each model field since database needs default value

--

Balaji Shetty

unread,
May 27, 2019, 10:12:19 PM5/27/19
to django...@googlegroups.com
Hi

You may change elogin column syntax and provide default="Some_Value" .This may work.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
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...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.


--
Mr Shetty Balaji
Asst. Prof.
IT Department
SGGS I&T
Nanded. My. India

Joe Reitman

unread,
May 28, 2019, 12:34:05 PM5/28/19
to Django users
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
Reply all
Reply to author
Forward
0 new messages