Ticket #350 (closed defect: worksforme)

Opened 6 years ago

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

Problem seems to be that for the fk field, field.rel.to 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 6 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 6 years ago by andrew

  • Status changed from assigned to infoneeded

comment:3 Changed 6 years ago by andrew

  • Status changed from infoneeded to closed
  • Resolution set to worksforme
Note: See TracTickets for help on using tickets.