First time here? Check out the FAQ!
1

Problem applying Migrations 24 and 25

arghhh
Trying to migrate from 0.6.17 to 0.6.48 - Straight environment - mysql backend

UPDATE: I have updated to the latest version, and migration 24 now works. However, 25 still fails.
I've decided to delve more deeply in this, and here is my findings:

There are some issues in the migration itself:

xxx> python manage.py migrate askbot
 Running migrations for askbot:
  - Migrating forwards to 0032_auto__del_field_badgedata_multiple__del_field_badgedata_description__d.
  > askbot:0025_transfer_flagged_items_to_activity
 - Migration 'askbot:0025_transfer_flagged_items_to_activity' is marked for no-dry-run.
  ! Error found during real run of migration! Aborting.
...
    File "...askbot/migrations/0025_transfer_flagged_items_to_activity.py", line 35, in forwards
      assert(activity.content_type==flag.content_type)
    File "...django/db/models/fields/related.py", line 244, in __get__
      raise self.field.rel.to.DoesNotExist

Issue 1:

Line 35: assert(activity.content_type==flag.content_type)

The tables activity and flagged_item don't have content_type field. They have "content_type_id" fields. Same with user vs. user_id, but that one doesn't complain.

Issue 2:
Once that was fixed, I ran into the assertion failure where content type is different!

Here is the entire flagged_item table:

mysql> select * from flagged_item;
+-----------+---------------------+----+-----------------+---------+
| object_id | flagged_at          | id | content_type_id | user_id |
|       166 | 2010-11-01 15:55:02 | 1  |              21 |      10 |
+-----------+---------------------+----+-----------------+---------+

mysql> select * from activity where object_id=166;
| is_audited | object_id | user_id | content_type_id | active_at     | id  | activity_type | question_id |
+--------------------------------------------------------------------------------------------------------+
|          0 |       166 |       3 |              26 | 2010-10-28 12:| 432 |             2 |         155 |
|          0 |       166 |       3 |              21 | 2010-10-28 16:| 458 |             1 |         166 |
+--------------------------------------------------------------------------------------------------------+

There seems to be some data inconsistency: - User Id in the Flagged_item and the activity table is different, so that assert should fail no?
- Same object_id for 2 activity entries, but the question_id are different - note that 1 question is flagged, and 1 answer is also flagged (to the same question). Is this an edge case I'm running into?

Benoit's avatar
875
Benoit
updated 2011-03-01 09:30:25 -0600, asked 2010-12-23 18:44:34 -0600
edit flag offensive 0 remove flag close merge delete

Comments

thanks, there is a bug in the migration 24, I'll fix it shortly.
Evgeny's avatar Evgeny (2010-12-23 19:18:29 -0600) edit
do you have a data backup? I think you are not starting from the same condition as before, because the first time #24 was broken, and now it is #23. I'd take a look at your data if it is possible. There is a command "python manage.py migrate --list" that tells which migrations are pending and which have been applied. Is there any inconsistency in that respect?
Evgeny's avatar Evgeny (2010-12-23 21:18:22 -0600) edit
actually, I did change the DB from the original (a couple of comments), but I reverted exactly to the original state right now (other than changing the db name). It still barfs. It's applying migration 22 ok (no-op) and stops at 23. Almost looks like the old askbot_activitystatus table is not dropped.
Benoit's avatar Benoit (2010-12-23 21:51:02 -0600) edit
there is another command - "python manage.py migrate #### --fake" where #### is the migration number in four digits. you can try to fake the 23rd and try applying others for real. Also examining the dump file may help figure out which migrations must be applied for real and which should be faked. Is your production forum running ok?
Evgeny's avatar Evgeny (2010-12-23 22:34:12 -0600) edit
thanks. I'll try that after the holidays
Benoit's avatar Benoit (2010-12-24 09:19:21 -0600) edit
add a comment see more comments

2 Answers

0

could you try version 0.6.49 (just updated on pypi)? does the migration work now?

also - in that new version are commands dump_forum and load_forum, you can use them to transfer the data to PostgresQL.

Thanks again.

Evgeny's avatar
13.2k
Evgeny
updated 2010-12-23 21:01:32 -0600, answered 2010-12-23 19:54:49 -0600
edit flag offensive 0 remove flag delete link

Comments

Looks like this is caused by the empty activity_items list. Looks like some fields are not set. I'll provide an answer with the (simple) source mods that worked for me. You might want to validate that it does what it should :)
Benoit's avatar Benoit (2011-01-03 14:43:27 -0600) edit
add a comment see more comments
1

In migration file, line 25. Replace

activity = orm.Activity(
  user = flag.user,
  active_at = flag.flagged_at,
  activity_type = OFFENSIVE
)
with
activity = orm.Activity(
  user = flag.user,
  active_at = flag.flagged_at,
  activity_type = OFFENSIVE,
  content_type = flag.content_type,
  object_id = flag.object_id
)

Benoit's avatar
875
Benoit
answered 2011-01-03 14:46:51 -0600
edit flag offensive 0 remove flag delete link

Comments

Thanks! I've added this fix to the updated version.
Evgeny's avatar Evgeny (2011-01-03 19:49:35 -0600) edit
add a comment see more comments