DAL IntegrityError

33 views
Skip to first unread message

annet

unread,
Nov 25, 2008, 10:13:54 AM11/25/08
to web2py Web Framework
The following lines of code are part of my model:

db.define_table('sleutelwoord',
SQLField('woord', length=20, notnull=True, unique=True),
SQLField('verzameling', type='integer', length=1, notnull=True,
unique=True),
migrate='sleutelwoord.table')


db.define_table('event',
SQLField('bedrijf', db.bedrijf, notnull=True),
SQLField('event', length=50, notnull=True),
SQLField('vandatum', type='date', notnull=True,),
SQLField('totdatum', type='date', notnull=True),
SQLField('duur', length=10, notnull=True),
SQLField('plaatsnaam', length=40, notnull=True),
SQLField('locatie', length=50),
SQLField('omschrijving', type='text'),
SQLField('sleutelwoord', db.sleutelwoord, notnull=True,
ondelete='RESTRICT'),
SQLField('doelgroep', db.doelgroep, notnull=True,
ondelete='RESTRICT'),
SQLField('scope', db.scope, notnull=True, ondelete='RESTRICT'),
migrate='event.table')

db.event.sleutelwoord.requires=IS_IN_DB(db, 'sleutelwoord.id', '%
(woord)s')


When I removed the unique=True constraint from the sleutelwoord tabel
and saved the model, it raised the following error:

S'Traceback (most recent call last):\n File "/Library/Python/2.5/site-
packages/web2py/gluon/restricted.py", line 62, in restricted\n exec
ccode in environment\n File "/Library/Python/2.5/site-packages/web2py/
applications/b2c/models/db.py", line 147, in <module>\n migrate=
\'sleutelwoord.table\')\n File "/Library/Python/2.5/site-packages/
web2py/gluon/sql.py", line 558, in define_table\n raise e
\nIntegrityError: column "verzameling__tmp" contains null values


At the moment the error was raised, the table contained one record:

values: 1,event,2

so no null values, as far as I can judge. Since I have experienced
this problem a couple of times before, I consider it worth a post.

This brings me to one of my greatest worries, I am working with web2py
and postgres on Mac OS 10.5.4 and every now and then the DAL got me
confused, simple changes like the one above raise errors I do not
understand. My postgres database contains example records for
development purposes, so it is no big deal to drop and re-create some
tables every now and then. But what when these errors occur after
deployment on a production server.

After initial deployment, when I continue developing my application,
the database in my development environment will start to differ from
the one on the production server. When I redeploy my application on
the production server, the files that make up the model match my
development database, but not my production database. How does web2py
deal with these differences?

I hope one of you can reassure me.

Best regards,

Annet.

mdipierro

unread,
Nov 25, 2008, 10:33:23 AM11/25/08
to web2py Web Framework
I think the problem is that you have a notnull column without default.
This causes a problem when doing a migration.

annet

unread,
Nov 27, 2008, 12:41:03 PM11/27/08
to web2py Web Framework
Massiomo,

Indeed I have notnull columns without defaults, I had a look at them
and for most of them I cannot think of a suitable default, so I wonder
whether setting the default with an empty string will suffice to solve
the problem.

Annet.

mdipierro

unread,
Nov 27, 2008, 12:57:15 PM11/27/08
to web2py Web Framework
yes it will.
Reply all
Reply to author
Forward
0 new messages