Modify ↓
Ticket #350 (closed defect: worksforme)
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: |
Description
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):
pass
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
t.save()
one gets an error with
File "./manage.py", line 11, in <module>
execute_manager(settings)
File "/home/tommi/asdf/virtualenv/src/django/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/home/tommi/asdf/virtualenv/src/django/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
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
migration_function()
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
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

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