Reputation: 137
I am using django and sqlite to create a simple shop. I have a model with nullable foreign key. But when i want to add an item using admin it stops me in the foreign key field. Please help, because i don't understand why it doesn't work:
class Item(models.Model):
id_order = models.ForeignKey(Order, null = True, default = None)
name = models.CharField(max_length = 100)
type_item = models.CharField(max_length = 50)
other = models.CharField(max_length = 200)
color = models.CharField(max_length = 100)
cost = models.IntegerField(default = 0)
is_available_now = models.BooleanField(default = False)
available_count = models.IntegerField(default = 0)
photo = models.ImageField(upload_to = "images/")
Upvotes: 3
Views: 6630
Reputation: 51715
You miss blank=True
in foreign key field. null
is just to database: https://docs.djangoproject.com/en/1.8/ref/models/fields/
Upvotes: 9