After importing data from a StackExchange site, I am seeing python errors when trying to edit some nodes. Specifically, post.active_revision is None in the __init__ method of RevisionForm in qanda.py. I looked in the database and found that there is no row in forum_noderevision with node_id equal to that of the row in forum_node. Should there be?

I have not updated my osqa code since last fall and am in no state to do this right now, so perhaps this is a problem that has already been solved.

asked 11 Mar '11, 12:57

gperrow's gravatar image

gperrow
24651523
accept rate: 25%

Yeah, we suck for not responding immediately on the weekend.

(14 Mar '11, 10:47) rickross ♦♦

There's a few solutions to fix your database, the best one is probably to enter the django shell:

python manage.py shell

And then try something like this:

from forum.models import *
for n in Node.objects.all():
    if not n.active_revision:
        r = NodeRevision(
            body=n.body,
            title=n.title,
            tagnames=n.tagnames,
            author=n.author,
            revised_at=n.added_at,
            revision=1,
            summary='initial revision',
            node=n
        )
        r.save()
        n.active_revision=r
        n.save()

Obviously backup your database before doing this.

Alternatively, you can save that code into a .py file and import it through the django shell.

link

answered 21 Mar '11, 09:52

Hernani%20Cerqueira's gravatar image

Hernani Cerq... ♦♦
16.8k65975
accept rate: 52%

You da man Hernâni! The code above worked perfectly. Thanks

(21 Mar '11, 10:12) gperrow

@gperrow, I believe this problem was addressed in an OSQA update some time ago. You can definitely now edit revisions of questions that were imported from SE. It works in the beta2 release that is currently available.

http://svn.osqa.net/changelog/OSQA?cs=756

link

answered 14 Mar '11, 10:46

rickross's gravatar image

rickross ♦♦
12.5k2914972
accept rate: 46%

OK, but since I have already done the import, is there any way to fix the existing database?

(14 Mar '11, 11:36) gperrow

I don't know of any silver bullet that will align your db schema with the current codebase and fill in the gaps in your existing data. DZone's team could probably help with this, but we should take that offline if you'd like to discuss it.

(14 Mar '11, 14:27) rickross ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×38
×18
×6

Asked: 11 Mar '11, 12:57

Seen: 570 times

Last updated: 21 Mar '11, 10:12

powered by OSQA