Ticket #350 (closed defect: worksforme)

Opened 4 years ago

Last modified 4 years ago

Creating foreign key relations in datamigrations fail

Reported by: tommi@… Owned by: andrew
Priority: major Milestone: 0.7
Component: databaseapi Version: 0.7-pre
Keywords: Cc:


I was actually trying to find out why reverse foreign key relations don't work and bumped into this:

App: buggy

from django.db import models

class Problem(models.Model):

class Target(models.Model):
    problem = models.ForeignKey('Problem', related_name='targets')

Now, when running a datamigration with

        p = orm.Problem.objects.create()
        t = orm.Target()
        t.problem = t    

one gets an error with

  File "./", line 11, in <module>
  File "/home/tommi/asdf/virtualenv/src/django/django/core/management/", line 438, in execute_manager
  File "/home/tommi/asdf/virtualenv/src/django/django/core/management/", line 379, in execute
  File "/home/tommi/asdf/virtualenv/src/django/django/core/management/", line 195, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/tommi/asdf/virtualenv/src/django/django/core/management/", line 222, in execute
    output = self.handle(*args, **options)
  File "/home/tommi/asdf/virtualenv/src/south/south/management/commands/", line 102, in handle
    delete_ghosts = delete_ghosts,
  File "/home/tommi/asdf/virtualenv/src/south/south/migration/", line 177, in migrate_app
    success = migrator.migrate_many(target, workplan)
  File "/home/tommi/asdf/virtualenv/src/south/south/migration/", line 207, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations)
  File "/home/tommi/asdf/virtualenv/src/south/south/migration/", line 272, in migrate_many
    result = self.migrate(migration)
  File "/home/tommi/asdf/virtualenv/src/south/south/migration/", line 119, in migrate
    result =
  File "/home/tommi/asdf/virtualenv/src/south/south/migration/", line 93, in run
    return self.run_migration(migration)
  File "/home/tommi/asdf/virtualenv/src/south/south/migration/", line 75, in run_migration
  File "/home/tommi/asdf/virtualenv/src/south/south/migration/", line 54, in <lambda>
    return (lambda: direction(orm))
  File "/home/tommi/asdf/asdf/buggy/migrations/", line 12, in forwards
    t.problem = t
  File "/home/tommi/asdf/virtualenv/src/django/django/db/models/fields/", line 291, in __set__
    elif value is not None and not isinstance(value,
TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types

Problem seems to be that for the fk field, isn't a type but just the string 'buggy.problem'...

Django used: 1.2 beta 1 SVN-12437
South: 635:eb57707fb001


Change History

comment:1 Changed 4 years ago by andrew

  • Status changed from new to assigned
  • Milestone set to 0.7

I've literally just pushed [7a34a4273ca5] for a very, very similar issue; could you check to see if it still fails?

comment:2 Changed 4 years ago by andrew

  • Status changed from assigned to infoneeded

comment:3 Changed 4 years ago by andrew

  • Status changed from infoneeded to closed
  • Resolution set to worksforme

Add a comment

Modify Ticket

as closed

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.