There is not enough information here, but this seems like a DB problem rather than a web2py code error.
You do not mention which DB.
It is not clear why you are re-building or importing to new tables etc.
When I upgraded (years ago), I do not recall touching my DB at all (Firebird).