"You are trying to add a non-nullable field 'form_ptr' to aboutpage without a default;"

2,037 views
Skip to first unread message

Tom Tanner

unread,
Oct 15, 2017, 11:05:15 PM10/15/17
to Mezzanine Users
Here's what my Mezzanine theme's `models.py` looks like.

from __future__ import unicode_literals


from django.db import models
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _


from mezzanine.conf import settings
from mezzanine.core.fields import FileField, RichTextField
from mezzanine.core.models import Displayable, Ownable, RichText, Slugged
from mezzanine.generic.fields import CommentsField, RatingField
from mezzanine.utils.models import AdminThumbMixin, upload_to
from mezzanine.forms.models import Form


class AboutPage(Form):
 
'''
 All-in-one about page
 '''



 site_description
= RichTextField(_("About"), help_text=_("A short description of this website."))


 
class Meta:
 verbose_name
=_("About page")
 verbose_name_plural
=_("About pages")

When I run `python manage.py makemigrations`, I get this message.

You are trying to add a non-nullable field 'form_ptr' to aboutpage 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: 2


How do I change my `AboutPage` class to avoid this message? 

My goal is to make a page that where I can put a form with descriptions and other info for my site. 

Rainell Dilou Gómez

unread,
Oct 16, 2017, 12:56:41 PM10/16/17
to Mezzanine Users
When you add a field to an existing model and run makemigrations, if you have not explicitly specified the default value for the new field, Django asks you what data will you put by default in the new field. If you don't want Django ask to you, you can edit the migration file manually, but ... why make manually something that Django can do for you? ;-)
Then you have 2 options, or specify explicitly the default value for the new field using default='your_value', or you answer to Django when ask you what value to set by default.

Tom Tanner

unread,
Oct 17, 2017, 12:36:33 AM10/17/17
to Mezzanine Users
In this case, what is `form_ptr`? It isn't a field I defined anywhere, as far as I know....

Rainell Dilou Gómez

unread,
Oct 17, 2017, 4:22:44 AM10/17/17
to Mezzanine Users
I think the answer to this question can be useful to you.

Why does my django formset need a pointer field reference?


Il giorno lunedì 16 ottobre 2017 05:05:15 UTC+2, Tom Tanner ha scritto:
Message has been deleted

Tom Tanner

unread,
Oct 20, 2017, 6:56:28 PM10/20/17
to Mezzanine Users
In that case, what must I add to `models.py`? If this was pure Django, it seems I'd need to add a dictionary of fields, including `form_ptr`. But what's the correct way in Mezzanine?

Tom Tanner

unread,
Oct 21, 2017, 2:47:45 PM10/21/17
to Mezzanine Users
I commented out my model, ran the migration commands, uncommented, ran the commands again, and things are fine

Nethra Gunti

unread,
Jun 8, 2020, 4:04:00 PM6/8/20
to Mezzanine Users
Hey, were you actually able to solve it? because any further changes I make are'nt reflected in the database!!!
Reply all
Reply to author
Forward
0 new messages