This may be way off-base, but can you check your model to make sure the line you have below as:

Field('year', 'string', requires=IS_NOT_EMPTY()),

is not mistakenly typed as:

Field('yearstring', requires=IS_NOT_EMPTY()),

Also, for string fields you don't need to specify the type ('string'), that is the default. I typically add a length to it as follows:

Field('year', length=4, requires=IS_NOT_EMPTY()),

    -Jim

On 5/21/2012 2:40 PM, Brandon Reynolds wrote:
How do I insert the value into that yearstring field? I understand i got the key error because of the field not being defined. I was trying that only as a troubleshooting step to see what happened. Should i make a yearstring field in the db and then just assing it a default value? Or how else to i get the value into that field? I also have another form that works fine on the site and it doesn't have yearstring field. Please advise.

On Monday, May 21, 2012 12:07:42 PM UTC-6, Anthony wrote:

    In your model, there is no "yearstring" field defined (there is a
    "year" field, though) -- so that's why you get a key error when
    trying to set db.home.yearstring.default. You might be getting the
    integrity error because the database itself does include a
    "yearstring" field (with a notnull requirement), and you are not
    inserting any value for that field.

    Anthony

    On Monday, May 21, 2012 1:08:25 PM UTC-4, Brandon Reynolds wrote:

        Hello,

        I am new to web2py and pretty new to programming in general. I
        am getting the following error when trying to insert a new
        record with a form made with crud.create:


                <class 'sqlite3.IntegrityError'> home.yearstring may
                not be NULL


        I have nothing in my model/view/controllers at all that
        mentions the year string. I tried to set yearstring a default
        value with db.home.yearstring.default = "0" but then got a key
        error that year string was not defined. Here is my controller
        for this view:

        @auth.requires_membership('Admin')
        def new_home():
            db.home.pid.default = request.args(0) or
        redirect(URL('parks'))
            db.home.price.default = "$0000.00"
            form = crud.create(db.home, next='home/[id]')
            return locals()

        Here is the model for this controller:

        db.define_table('home',
        Field('pid', notnull=True),
        Field('lot', 'string'),
        Field('year', 'string', requires=IS_NOT_EMPTY()),
        Field('make', 'string'),
        Field('model', 'string'),
        Field('for_sale', 'boolean', default=True),
        Field('beds', 'string', requires=IS_NOT_EMPTY()),
        Field('baths', 'string', requires=IS_NOT_EMPTY()),
        Field('fridge', 'boolean'),
        Field('stove', 'boolean'),
        Field('dishwasher', 'boolean'),
        Field('microwave', 'boolean'),
        Field('washer', 'boolean'),
        Field('dryer', 'boolean'),
        Field('photo1', 'upload'),
        Field('photo2', 'upload'),
        Field('photo3', 'upload'),
        Field('photo4', 'upload'),
        Field('photo5', 'upload'),
        Field('price', 'string' , requires=IS_NOT_EMPTY()),
        Field('description', 'text', requires=IS_NOT_EMPTY()))

        Also here is the traceback.

        Traceback(most recent call last):
           File"gluon/restricted.py",line205,inrestricted
           
File"/Applications/web2py.app/Contents/Resources/applications/pages/controllers/view.py"  
<http://127.0.0.1:8000/admin/default/edit/pages/controllers/view.py>,line110,in<module>
           File"gluon/globals.py",line173,in<lambda>
           File"gluon/tools.py",line2575,inf
           
File"/Applications/web2py.app/Contents/Resources/applications/pages/controllers/view.py"
  <http://127.0.0.1:8000/admin/default/edit/pages/controllers/view.py>,line88,innew_home
           File"gluon/tools.py",line3172,increate
           File"gluon/tools.py",line3115,inupdate
           File"gluon/sqlhtml.py",line1274,inaccepts
           File"gluon/dal.py",line6829,ininsert
           File"gluon/dal.py",line928,ininsert
        IntegrityError:home.yearstring maynotbe NULL


        What is this error ad how can i get around it?

Reply via email to