1
When creating an id manually you should use AutoField instead of IntegerField
id_dato = models.AutoField(primary_key=True)
https://docs.djangoproject.com/en/1.6/ref/models/fields/#autofield
What is happening is that since you are not explicitly defining the ‘datos’ object’s id it doesnt have one, and then producto complains because the key can’t have an empty value.
AutoField should fix this
0
I am surprised it doesn’t fail at the earlier line: datos.save()
because you have not supplied a value for the primary key datos.id_dato
Normally in Django you would need to use an AutoField
to get an auto-incrementing primary key.
Also you should not be specifying primary_key=True
on the OpeProductos.iddato
field, you can only have one primary key per model.
Then the error you are seeing is due to the fact that datos.id_dato
is None
since you did not provide any value for it before saving the datos
instance.
- [Answer]-Django querying from 3 models
- [Answer]-Django-cms placeholder outside cms – how to get related model using the placeholder from the one model that is connected?
- [Answer]-Pass Data From Python To Html <p> Tag