2

I am running datamigrations for my project. My aim is to make a user follow all his articles which were created before the activity stream was implemented

I had created the migration file using the command

python manage.py datamigration articles das_user_migrate_data --freeze auth --settings=maldio_project.settings.dev_keval 

for the forward function I have the following code,

def forwards(self, orm):
        registry.register(orm['articles.article'])
        for articles in orm['articles.article'].objects.all():
            user = orm['auth.User'].objects.get(username=article.submitter.username)
            follow(user, article, actor_only=False)

I have the proper imports needed for the operation. But while running the migrate command I get the following error

ValueError: Cannot assign "<User: User object>": "Follow.user" must be a "User" instance.

I have seen other questions with the same error but the solutions mentioned didn't work for me.

Keval Doshi
  • 738
  • 6
  • 25

1 Answers1

0

Without seeing your "follow" function I'd say that the class of the User you're trying to assign to the Follow object instance is not the same as you are referencing in the FK of Follow.

Make sure you didn't subclass Django's User. See django: must be a User Instance when trying to save, but it is!

Community
  • 1
  • 1
dukebody
  • 7,025
  • 3
  • 36
  • 61
  • thanks for the suggestion, but I am not extending the `auth.User` class in my code and the `foreign key` is properly mapped to the `auth.user` – Keval Doshi Oct 25 '14 at 12:43
  • You might have taken the str representation of the User object in the 'follow' function? Could you please add the definition of the 'follow' function to your question? – dukebody Oct 25 '14 at 12:57
  • the `follow` function is a part of the `django-activity-stream` which I am trying to integrate with my project – Keval Doshi Oct 25 '14 at 13:05
  • Looking at the code of django-activity-stream it sounds like it is trying to create a _new_ Follow object pointing to a _historical_ User (that's why you get "" instead of the common username User object representation). See http://stackoverflow.com/questions/26542617/how-can-i-send-signals-from-within-django-migrations Have you tried freezing the django-activity-stream Follow model as well? – dukebody Oct 25 '14 at 13:44