For some reason on Localhost (LH) everything works fine but on my Production server, my form does not add a new user submission properly. The error I am getting is:
duplicate key value violates unique constraint "..."
DETAIL: Key (id)=(8) already exists.
Is there some sort of production "sudo systemctl restart gunicorn" I need to run (I have already tried the example above)? Maybe it's only working on LH because there I have tested there more and the increment naturally fell on the same level as the total amount of users? I really am out of ideas here.
models.py
class Lead(models.Model):
username = models.CharField(max_length=15, blank=True, null=True)
email = models.CharField(unique=True, max_length=150, validators=[validate_email])
created = models.DateTimeField(auto_now_add=True)
...
forms.py
class LeadCaptureForm1(forms.ModelForm):
birth_date = forms.DateField(widget=SelectDateWidget(years=range(1999, 1910, -1)))
class Meta:
model = Lead
widgets = {
'email': forms.TextInput(attrs={'class': 'form-control'}),
}
fields = ('email', 'birth_date',)
views.py
def iframe1(request):
ip = get_real_ip(request)
created = timezone.now()
if request.method == 'POST':
form = LeadCaptureForm1(request.POST)
if form.is_valid():
# Save lead
lead = form.save()
# attempt at fixing it
#lead.id = Lead.objects.get(all).count()
#print(lead.id)
lead.created = created
lead.birth_date = form.cleaned_data.get('birth_date')
lead.ipaddress = get_real_ip(request)
lead.joinmethod = "Iframe1"
lead.save()
print(lead)