Re: Foreign Key problems with legacy database

2013-07-23 Thread Nick Dokos
Avraham Serour  writes:

> you don't need songid = models.Integerfield()

... and the ForeignKey should not specify a db_column.

>
> On Tue, Jul 23, 2013 at 6:04 AM, Brian Millham  wrote:
>
> I have the following models:
>
> class Requestlist(models.Model):
>    id = models.IntegerField(primary_key=True)
>    songid = models.Integerfield()
>    song = ForeignKey('Song', db_column='songid')
> class Song(models.Model):
>   id = models.IntegerField(primary_key=True)
>   title = models.CharField(max_length=255L)
>
--
Nick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Foreign Key problems with legacy database

2013-07-23 Thread Avraham Serour
you don't need songid = models.Integerfield()


On Tue, Jul 23, 2013 at 6:04 AM, Brian Millham  wrote:

> I have the following models:
>
> class Requestlist(models.Model):
>>id = models.IntegerField(primary_key=True)
>>songid = models.Integerfield()
>>song = ForeignKey('Song', db_column='songid')
>> class Song(models.Model):
>>   id = models.IntegerField(primary_key=True)
>>   title = models.CharField(max_length=255L)
>
>
> The relation should be Requestlist.songid = Song.id
>
> The above models seem to work for querying, but when I create a new
> requestlist, via a form, then I get the error that: Column songid specified
> twice.
>
> If I remove the ForeignKey, I can save the requestlist, but obviously I
> lose the relations.
>
> I've tried replacing the db_column='songid' with to_field='id' but that's
> worse. The relation then totally breaks.
>
> It's gotta be something simple that I'm overlooking
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Foreign Key problems with legacy database

2013-07-22 Thread Brian Millham
I have the following models:

class Requestlist(models.Model):
>id = models.IntegerField(primary_key=True)
>songid = models.Integerfield()
>song = ForeignKey('Song', db_column='songid')
> class Song(models.Model):
>   id = models.IntegerField(primary_key=True)
>   title = models.CharField(max_length=255L)


The relation should be Requestlist.songid = Song.id

The above models seem to work for querying, but when I create a new 
requestlist, via a form, then I get the error that: Column songid specified 
twice.

If I remove the ForeignKey, I can save the requestlist, but obviously I 
lose the relations.

I've tried replacing the db_column='songid' with to_field='id' but that's 
worse. The relation then totally breaks. 

It's gotta be something simple that I'm overlooking

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Foreign key problems with legacy database

2013-07-22 Thread Brian Millham
I have these 2 models:

class Requestlist(model.Model):

 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.