Monday, January 4, 2016

Re: EmailField: unable to make it mandatory?

Le 04/01/2016 08:55, James Schneider a écrit :
>
> On Jan 3, 2016 9:02 PM, "gerard" <gh224391@gmail.com
> <mailto:gh224391@gmail.com>> wrote:
> >
> > Hello all and happy new year,
> >
> > with Django 1.7, i have this model:
> > class Subscription(models.Model):
> > email = models.EmailField(max_length=75)
> > created_by = models.ForeignKey(User)
> >
> > sub = Subscription.objects.create(created_by=self.user)
> > this does not product an error due to email missing.
> >
> > I also tried:
> > email = models.EmailField(max_length=75, null=False, blank=False)
> > without success
> >
> > The database is postgresql, the command "manage.py sql" shows:
> > CREATE TABLE "eventsmgmt_subscription" (
> > "email" varchar(75) NOT NULL,
> >
> > in fact, the email is filled with a null string ''.
> >
> > How can i deal with this?
> >
> >
> > Thanks in advance for help,
> >
> > --
> > Gérard Henry
>
> Did you run 'makemigrations' and 'migrate' after making those changes to
> your model? I suspect you didn't.
>

yes, i did

> The output of the 'sql' command only shows what would be run if you ran
> a 'migrate' command, and does not reflect the current state of the database.
>

i looked into database directly:
foo=> \d eventsmgmt_subscription
Table «
public.eventsmgmt_subscription »
Colonne | Type |
Modificateurs
---------------------+--------------------------+--------------------------------------------------------------------------
id | integer | non NULL Par défaut,
nextval('eventsmgmt_subscription_id_seq'::regclass)
created_by_id | integer | non NULL
email | character varying(75) | non NULL

as you can see, "not NULL" is in the table


thanks for reply,

--
Gérard Henry

--
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/568A27E5.8090407%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment