I have an issu with django, when I run django shell, and try to add some value in my database, I have an error. I used python manage.py migrations and python manage.py migrate before.
>from store.models import Marque, Model
charger = Model(name="Charger")
charge.save()
--- then I have this error, it work fine if I create "Marque" object
Null value in column “marque_id” violates not-null constraint
from django.db import models
# Create your models here.
class Contact(models.Model):
email = models.EmailField(max_length=100)
name = models.CharField(max_length=200)
class Marque(models.Model):
name = models.CharField(max_length=200, unique=True)
class Model(models.Model): #Multiples Model to One Marque
reference = models.IntegerField(null=True)
created_at = models.DateTimeField(auto_now_add=True)
available = models.BooleanField(default=True)
name = models.CharField(max_length=200)
picture = models.URLField()
marque = models.ForeignKey(Marque, on_delete=models.CASCADE)
class Booking(models.Model): #mutliples Booking to one Contact
created_at = models.DateTimeField(auto_now_add=True)
contacted = models.BooleanField(default=False)
marque = models.OneToOneField(Marque, on_delete=models.CASCADE)
model = models.OneToOneField(Model, on_delete=models.CASCADE)
contact = models.ForeignKey(Contact, on_delete=models.CASCADE)
Requirement.txt: Django==2.1.7 django-debug-toolbar==1.11 psycopg2==2.7.7 psycopg2-binary==2.7.7 pytz==2018.9 sqlparse==0.2.4