Move writing unknown column exception to null attribute

Making this change revealed several subtle bugs related to models with
no primary key, and anonymous classes. These have been fixed as well,
with regression tests added.
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/model_schema.rb#L326

Should probably be fixed there. This is turning into a rabbit hole. :cry: