Ask Your Question
1

Problem applying Migrations 24 and 25

asked 2010-12-23 18:44:34 -0500

Benoit gravatar image

updated 2011-03-01 09:30:25 -0500

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?

edit retag flag offensive close merge delete

Comments

thanks, there is a bug in the migration 24, I'll fix it shortly.
Evgeny gravatar imageEvgeny ( 2010-12-23 19:18:29 -0500 )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 gravatar imageEvgeny ( 2010-12-23 21:18:22 -0500 )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 gravatar imageBenoit ( 2010-12-23 21:51:02 -0500 )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 gravatar imageEvgeny ( 2010-12-23 22:34:12 -0500 )edit
thanks. I'll try that after the holidays
Benoit gravatar imageBenoit ( 2010-12-24 09:19:21 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2011-01-03 14:46:51 -0500

Benoit gravatar image

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
)

edit flag offensive delete link more

Comments

Thanks! I've added this fix to the updated version.
Evgeny gravatar imageEvgeny ( 2011-01-03 19:49:35 -0500 )edit
0

answered 2010-12-23 19:54:49 -0500

Evgeny gravatar image

updated 2010-12-23 21:01:32 -0500

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.

edit flag offensive delete link more

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 gravatar imageBenoit ( 2011-01-03 14:43:27 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2010-12-23 18:44:34 -0500

Seen: 427 times

Last updated: Jan 05 '11