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", line 205, in restricted
>   File 
> "/Applications/web2py.app/Contents/Resources/applications/pages/controllers/view.py"
>  <http://127.0.0.1:8000/admin/default/edit/pages/controllers/view.py>, line 
> 110, in <module>
>   File "gluon/globals.py", line 173, in <lambda>
>   File "gluon/tools.py", line 2575, in f
>   File 
> "/Applications/web2py.app/Contents/Resources/applications/pages/controllers/view.py"
>  <http://127.0.0.1:8000/admin/default/edit/pages/controllers/view.py>, line 
> 88, in new_home
>   File "gluon/tools.py", line 3172, in create
>   File "gluon/tools.py", line 3115, in update
>   File "gluon/sqlhtml.py", line 1274, in accepts
>   File "gluon/dal.py", line 6829, in insert
>   File "gluon/dal.py", line 928, in insert
> IntegrityError: home.yearstring may not be NULL
>
>
> What is this error ad how can i get around it?
>

Reply via email to