Using a frozen model to create foreign key

17 views
Skip to first unread message

Justin

unread,
Dec 1, 2009, 8:15:30 PM12/1/09
to South Users
Hello!

I'm loving South right now, it's made my life so much easier.

I"m running into this problem. Here's the models.

In app entity:
class Company(models.Model):
name = models.CharField()
...

In app matchmaking:
class CompanyProfile(models.Model):
company = models.OneToOneField(Company)
...

I'm working with the matchmaking app and I've frozen the entity app.

Here's my migration:

def forwards(self, orm):
"Write your forwards migration here"
for company in orm['entity.Company'].objects.all():
CompanyProfile.objects.get_or_create(company=company)

I'm getting an error that I need to pass in a Company object.
ValueError: Cannot assign "<company: company object>":
"CompanyProfile.company" must be a "Company" instance.

Am I doing this wrong? Any ideas?

Thanks!
Justin

Jukka Välimaa

unread,
Dec 2, 2009, 3:57:04 AM12/2/09
to south...@googlegroups.com
My hunch is that you should also freeze the matchmaking app to the migration with "--freeze", and use the frozen orm in getting company profile. The frozen orm models are not the same classes that you get by importing.


--

You received this message because you are subscribed to the Google Groups "South Users" group.
To post to this group, send email to south...@googlegroups.com.
To unsubscribe from this group, send email to south-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/south-users?hl=en.



Andrew Godwin

unread,
Dec 4, 2009, 4:52:40 AM12/4/09
to south...@googlegroups.com
Yes, Jukka is entirely right. You have to use the frozem version of
Company - i.e. orm['entity.Company'] - as it's a different model to the
one you imported (and for good reason - you might change Company in the
future).

Andrew
> <mailto:south...@googlegroups.com>.
> To unsubscribe from this group, send email to
> south-users...@googlegroups.com
> <mailto:south-users%2Bunsu...@googlegroups.com>.
Reply all
Reply to author
Forward
0 new messages