summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zielinski <tomasz.zielinski@pyconsultant.eu>2012-01-02 19:54:04 +0100
committerTomasz Zielinski <tomasz.zielinski@pyconsultant.eu>2012-01-02 19:54:04 +0100
commitcc8f3e89a7eb775fef862aaa27f7a9a648052c6a (patch)
tree2295ffb45c82ffe2bfb6bad81aa766f3d110e089
parenta260f129a080adcd0383d09e895c47a3edcda02e (diff)
downloadaskbot-cc8f3e89a7eb775fef862aaa27f7a9a648052c6a.tar.gz
askbot-cc8f3e89a7eb775fef862aaa27f7a9a648052c6a.tar.bz2
askbot-cc8f3e89a7eb775fef862aaa27f7a9a648052c6a.zip
Fixed migration 0095 which was failing for fresh databases
-rw-r--r--askbot/migrations/0095_postize_award_and_repute.py38
1 files changed, 22 insertions, 16 deletions
diff --git a/askbot/migrations/0095_postize_award_and_repute.py b/askbot/migrations/0095_postize_award_and_repute.py
index a65e5224..be74d688 100644
--- a/askbot/migrations/0095_postize_award_and_repute.py
+++ b/askbot/migrations/0095_postize_award_and_repute.py
@@ -11,24 +11,30 @@ class Migration(DataMigration):
if 'test' in sys.argv: # This migration fails when testing... Ah those: crappy Askbot test suite and broken Django test framework ;;-)
return
- ct_question = orm['contenttypes.ContentType'].objects.get(app_label='askbot', model='question')
- ct_answer = orm['contenttypes.ContentType'].objects.get(app_label='askbot', model='answer')
- ct_comment = orm['contenttypes.ContentType'].objects.get(app_label='askbot', model='comment')
+ if orm.Award.objects.exists():
+ # Note that for an empty database (most likely a fresh one)
+ # there are no contenttypes for Question/Answer/Comment models installed,
+ # because there are no such models anymore
+ # Therefore we only run this section if there are any Award-s to migrate,
+ # i.e. there is some legacy data and legacy contenttypes are likely to be present in the database
+ ct_question = orm['contenttypes.ContentType'].objects.get(app_label='askbot', model='question')
+ ct_answer = orm['contenttypes.ContentType'].objects.get(app_label='askbot', model='answer')
+ ct_comment = orm['contenttypes.ContentType'].objects.get(app_label='askbot', model='comment')
- ct_post = orm['contenttypes.ContentType'].objects.get(app_label='askbot', model='post')
+ ct_post = orm['contenttypes.ContentType'].objects.get(app_label='askbot', model='post')
- for aw in orm.Award.objects.all():
- ct = aw.content_type
- aw.content_type = ct_post
- if ct == ct_question:
- aw.object_id = orm.Post.objects.get(self_question__id=aw.object_id).id
- elif ct == ct_answer:
- aw.object_id = orm.Post.objects.get(self_answer__id=aw.object_id).id
- elif ct == ct_comment:
- aw.object_id = orm.Post.objects.get(self_comment__id=aw.object_id).id
- else:
- raise ValueError('Unknown award subject!')
- aw.save()
+ for aw in orm.Award.objects.all():
+ ct = aw.content_type
+ aw.content_type = ct_post
+ if ct == ct_question:
+ aw.object_id = orm.Post.objects.get(self_question__id=aw.object_id).id
+ elif ct == ct_answer:
+ aw.object_id = orm.Post.objects.get(self_answer__id=aw.object_id).id
+ elif ct == ct_comment:
+ aw.object_id = orm.Post.objects.get(self_comment__id=aw.object_id).id
+ else:
+ raise ValueError('Unknown award subject!')
+ aw.save()
###