Hi,
-- Maybe g() should return the id instead of the instance? That does seem a bit odd that it wouldn't accept an A() instance as the default.
Collin
On Wednesday, March 11, 2015 at 7:43:35 AM UTC-4, Krzysztof Ciebiera wrote:
On Wednesday, March 11, 2015 at 7:43:35 AM UTC-4, Krzysztof Ciebiera wrote:
I have created a model A:
def g():
return A.objects.get(pk=1)
class A(models.Model):
a = models.IntegerField()
./manage.py makemigrations
./manage.py migrate
then I've added some data:
a = A(a=1)
a.save()
then I have created another model with a ForeignKey field with a default set to g function (that really returns one instance od A) and I was trying to migrate it:
class B(models.Model):
b = models.ForeignKey(A, default=g)
./manage.py makemigrations
...
./manage.py migrate
....
File ".../e/local/lib/python2.7/site-packages/django/db/ models/fields/__init__.py", line 627, in get_db_prep_save
prepared=False)
File ".../e/local/lib/python2.7/site-packages/django/db/ models/fields/__init__.py", line 907, in get_db_prep_value
value = self.get_prep_value(value)
File ".../p/e/local/lib/python2.7/site-packages/django/db/ models/fields/__init__.py", line 915, in get_prep_value
return int(value)
TypeError: int() argument must be a string or a number, not 'A'
Is it expected behaviour or a bug?
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+unsubscribe@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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/877cc6a3-1b37-4b88-918b-a0f955f59c8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment