Fix upgrade path for attached DBs. Add logging.
Fix caching, wtf!

I discovered that caching has not been working for a while now while tracking down a bug. Models were being added to the cache before they had an Id, make the identifier "table@null" for all models added. Caching now works.