Django shell: Can't find constructor of a model
I have a Django Modell Kunde
from django.db import models
class Kunde(models.Model):
Kundennummer = models.IntegerField(),
Vorname = models.CharField(max_length=200),
Nachname = models.CharField(max_length=200)
I open the Django shell with the command python manage.py shell
I do
from kundenliste.models import Kunde;
and then
Kunde.objects.all()
This gives me
<QuerySet []>
Now I would like to insert a new customer
But
k1 = Kunde(Kundennummer=1,Vorname="Florian",Nachname="Ingerl");
gives me the error
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Users\imelf\Documents\NachhilfeInfoUni\MaxPython\env_site\Lib\site-packages\django\db\models\base.py", line 569, in __init__
raise TypeError(
TypeError: Kunde() got unexpected keyword arguments: 'Kundennummer', 'Vorname'
What do I do wrong?
Try Removing , after each field in the class Kunde. It is making Django think they are in same field
do this :
from django.db import models
class Kunde(models.Model):
Kundennummer = models.IntegerField()
Vorname = models.CharField(max_length=200)
Nachname = models.CharField(max_length=200)
AND then migrate those changes .
Remove the ,
(comma)
, adding a comma ,
after an expression makes it a tuple.
from django.db import models
class Kunde(models.Model):
Kundennummer = models.IntegerField()
Vorname = models.CharField(max_length=200)
Nachname = models.CharField(max_length=200)