0
我有一個公式化與mutiples模型和標記錯誤的時刻看守信息多模型IntegrityError
我離開他們,標誌着我的錯誤,當我嘗試看守信息
http://127.0.0.1:8000/register/cliente/
Django Version: 1.6.2
Exception Type: IntegrityError
Exception Value:
app_empresa.cliente_id may not be NULL
Exception Location: /usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py in execute, line 450
Python Executable: /usr/bin/python
Python Version: 2.7.3
Python Path:
['/home/servicio/www/frente',
'/usr/local/lib/python2.7/dist-packages/merengue-0.9.0-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_su-0.4.2-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/recaptcha_client-1.0.6-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_inplaceedit-0.82-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_classy_tags-0.3.0-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_compressor-1.1.2-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_autoreports-0.8.6-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_form_admin-0.4.2-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_configfield-0.2.2-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/searchform-0.1.3dev-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/sorl_thumbnail-11.12-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_transmeta-0.6.6-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_inlinetrans-0.6.0-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/transhette-0.5.10-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/cmsutils-0.6.6-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_stdfile-0.5-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_genericforeignkey-0.60.4-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_oot-0.8.4-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_announcements-0.1.2-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_notification-0.1.5-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_threadedcomments-0.5.3-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_ajax_selects-1.1.4-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_oembed-0.1.3-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_mptt-0.4.2-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_debug_toolbar-0.8.5-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/template_utils-0.4p2-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/johnny_cache-1.4-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_pagination-1.0.7-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_tagging-0.3.2-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/cssutils-1.0-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_extensions-0.5-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/South-0.7.3-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/python_twitter-0.8.2-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/feedparser-5.1.3-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/encutils-0.9-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/BeautifulSoup-3.2.0-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_appconf-0.6-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_jsonfield-0.8.11-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/polib-1.0.3-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/oauth2-1.5.211-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/six-1.5.2-py2.7.egg',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PIL',
'/usr/lib/python2.7/dist-packages/gst-0.10',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
'/usr/lib/python2.7/dist-packages/ubuntuone-client',
'/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
'/usr/lib/python2.7/dist-packages/ubuntuone-couch',
'/usr/lib/python2.7/dist-packages/ubuntuone-installer',
'/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol'
後來我離開他們我的模型
class Cliente(models.Model):
nombre = models.CharField(max_length=50)
apellido_Materno = models.CharField(max_length=50)
apellido_Paterno = models.CharField(max_length=50)
puesto = models.CharField(max_length=50)
telefono = models.IntegerField(max_length=10, unique=True, validators=[RegexValidator(regex='^\d{10}$', message='Debe de se de 10 digitos', code='Invalid number')])
mail = models.EmailField(max_length=75)
created = models.DateTimeField(auto_now_add=True)
def __unicode__(self):
return u'%s' % self.nombre
class Empresa(models.Model):
nombreEmpresa = models.CharField(max_length=100)
calle = models.CharField(max_length=100)
numero_Exterior = models.IntegerField()
numero_Interior = models.IntegerField(null=True)
Colonia = models.ForeignKey(Colonia)
delegacion = models.ForeignKey(Delegacion)
rutas = models.ManyToManyField(Ruta)
cliente = models.ForeignKey(Cliente)
categoria = models.ForeignKey(Categoria)
subcategoria1 = models.ForeignKey(Subcategoria1)
subcategoria2 = models.ForeignKey(Subcategoria2)
subcategoria3 = models.ForeignKey(Subcategoria3)
position = GeopositionField()
created = models.DateTimeField(auto_now_add=True)
我views.py
def register_cliente(request):
if request.method == "POST":
form_a = CreateCliente(request.POST, prefix="cli")
form_b = CreateEmpresa(request.POST, prefix="emp")
if form_a and form_b.is_valid():
cliente = form_a.save(commit = False)
cliente.empresa = form_b.save()
return HttpResponse('registro Realisado')
else:
form_a = CreateCliente(prefix="cli")
form_b = CreateEmpresa(prefix="emp")
context = {}
context.update(csrf(request))
context['form_a'] = form_a
context['form_b'] = form_b
#Pass the context to a template
return render_to_response('registercliente.html', context)
else:
form_a = CreateCliente(prefix="cli")
form_b = CreateEmpresa(prefix="emp")
return render(request, 'registercliente.html', {'form_a': form_a,'form_b': form_b})
我forms.py
class CreateCliente(ModelForm):
class Meta:
model = Cliente
fields = ('nombre','apellido_Paterno','apellido_Materno','puesto','telefono','mail')
class CreateEmpresa(ModelForm):
class Meta:
model = Empresa
fields = ('nombreEmpresa','calle','numero_Exterior','numero_Interior','Colonia','delegacion')
我的HTML
{% extends 'base.html' %}
{% block content %}
<form action="." method="POST">
{% csrf_token %}
{{ form_a.as_p }}
{{ form_b.as_p }}
<input type="submit" value="Guardar">
</form>
{% endblock %}
回溯,請。 – skzryzg