here is what happened:
1) you inserted records that had Null values for number
2) you added the attribute notnull=True but those records are still
there
3) you ask for a different length (which would require moving data
over)

before you do the migration run

db(db.address.number==None).update(number=0)

or set notnull=False


On Oct 29, 12:52 pm, annet <annet.verm...@gmail.com> wrote:
> In db.py I have the following table definition:
>
> db.define_table('address',
>     db.Field(..),
>     db.Field('number',length=6,default='',notnull=True),
>     db.Field(),
>     migrate='address.table')
>
> I needed to set the length of the number column to 9 characters:
>
> db.define_table('address',
>     db.Field(..),
>     db.Field('number',length=9,default='',notnull=True),
>     db.Field(),
>     migrate='address.table')
>
> When I save the new table definition and return to the database
> administration I get the following error:
>
> S'Traceback (most recent call last):\n  File "/Library/Python/2.5/site-
> packages/web2py/gluon/restricted.py", line 184, in restricted\n
> exec ccode in environment\n  File "/Library/Python/2.5/site-packages/
> web2py/applications/base/models/db.py", line 155, in <module>\n
> migrate=\'address.table\')\n  File "/Library/Python/2.5/site-packages/
> web2py/gluon/sql.py", line 1130, in define_table\n    query = t._create
> (migrate=migrate)\n  File "/Library/Python/2.5/site-packages/web2py/
> gluon/sql.py", line 1506, in _create\n    sql_fields_aux, logfile)\n
> File "/Library/Python/2.5/site-packages/web2py/gluon/sql.py", line
> 1558, in _migrate\n    self._db._execute(sub_query)\n  File "/Library/
> Python/2.5/site-packages/web2py/gluon/sql.py", line 835, in <lambda>
> \n    self._execute = lambda *a, **b: self._cursor.execute(*a, **b)
> \nIntegrityError: column "number__tmp" contains null values\n\n'
>
> I don't understand why I get this error, number was set to
> notnull=True in the first place, I only changed the number of
> characters form 6 to 9. Why does this break the model?
>
> I had to alter the number of characters manually in my Postgres
> database, and set migrate to False to get my model to work again,
> which means I cannot do any migrations from the address table in the
> future.
>
> Kind regards,
>
> Annet.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to