As with any migration there is a current situation and a new situation. The key 
to understanding the migration system is that Web2py doesn't query the database 
to find out what tables and fields your database contains, the current 
situation. The current situation is recorded in the .table files by Web2py. And 
the desired database structure is described in the model files. But how can 
this work?
When you start with an application  on a server, let's say your dev server, you 
create a table description in your model file, db.py. On the first run, 
assuming migrate is true, Web2py checks the content of the table files, if any 
exist, in this case none, created the tables in the empty database and records 
the table data in the .table files.

On the next runs Web2py keeps checking if the model files are in sync with the 
table files. If they're not, because you changed the model file it generates 
ALTER TABLE statements changing the database and if succesfull changing the 
notable files. So far so good.
If you install your app on another machine and include the database ( and not 
the .table files) Web2py (again if migrate is true) tries to create all tables, 
but fails, because they are already there.
The solution is to recreate the table files using the setting fake_migrate_all 
to be true. After that everything should be in sync again.

Note that in some situations it can be tricky to get back in sync. If you 
changed a table in the db management software, and not the model file, the 
migration steps will be incorrect. By checking the log files you can see what 
Web2py is trying to do and change the database or the model files to get back 
in sync.

As always please check the Web2py book at web2py.com, chapters migrations and 
fixing broken migrations for full details. I hope this description helps you to 
understand the basics. It not that difficult if you grasp it :-)

Nico de Groot 

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to