System: Ubuntu 12.4 LTS, Web2py 2.0.9, Postgres 9, psycopg2
In the model, start with a table like this:
db.define_table('subject_revisions',
Field('subject_id', 'reference subjects',
readable=False, writable=False,),
Field('revision', length=32),
Field('effective_date', 'date', requires=IS_EMPTY_OR(IS_DATE())),
)
We are going to attempt to change revision to a required integer.
First, comment it out so Postgres drops the column.
db.define_table('subject_revisions',
Field('subject_id', 'reference subjects',
readable=False, writable=False,),
# Field('revision', length=32),
Field('effective_date', 'date', requires=IS_EMPTY_OR(IS_DATE())),
)
Then put it back as an integer field.
b.define_table('subject_revisions',
Field('subject_id', 'reference subjects',
readable=False, writable=False,),
Field('revision', 'integer'),
Field('effective_date', 'date', requires=IS_EMPTY_OR(IS_DATE())),
)
Now using the admin interface, make sure that all entries in the table have
an integer value in the field.
Make the field required.
b.define_table('subject_revisions',
Field('subject_id', 'reference subjects',
readable=False, writable=False,),
Field('revision', length=32, required=True),
Field('effective_date', 'date', requires=IS_EMPTY_OR(IS_DATE())),
)
So far so good. Refresh the admin interface and observe no errors.
Now try to tell Postgres to not allow nulls. Make this change to the field
def:
Field('revision', length=32, required=True, notnull=True),
Postgres chokes with this error:
IntegrityError: column "revision__tmp" contains null values
Remove the notnull constraint and attempt to refresh the admin interface.
Rocket will hang at this point.
--