<bdo id='UytWu'></bdo><ul id='UytWu'></ul>
  • <legend id='UytWu'><style id='UytWu'><dir id='UytWu'><q id='UytWu'></q></dir></style></legend>

      <tfoot id='UytWu'></tfoot>
      1. <small id='UytWu'></small><noframes id='UytWu'>

        <i id='UytWu'><tr id='UytWu'><dt id='UytWu'><q id='UytWu'><span id='UytWu'><b id='UytWu'><form id='UytWu'><ins id='UytWu'></ins><ul id='UytWu'></ul><sub id='UytWu'></sub></form><legend id='UytWu'></legend><bdo id='UytWu'><pre id='UytWu'><center id='UytWu'></center></pre></bdo></b><th id='UytWu'></th></span></q></dt></tr></i><div id='UytWu'><tfoot id='UytWu'></tfoot><dl id='UytWu'><fieldset id='UytWu'></fieldset></dl></div>
      2. IntegrityError 在表“orders_order"上插入或更新违反外键约束“

        时间:2023-08-30
        <tfoot id='iLgI0'></tfoot>

          <tbody id='iLgI0'></tbody>

        1. <i id='iLgI0'><tr id='iLgI0'><dt id='iLgI0'><q id='iLgI0'><span id='iLgI0'><b id='iLgI0'><form id='iLgI0'><ins id='iLgI0'></ins><ul id='iLgI0'></ul><sub id='iLgI0'></sub></form><legend id='iLgI0'></legend><bdo id='iLgI0'><pre id='iLgI0'><center id='iLgI0'></center></pre></bdo></b><th id='iLgI0'></th></span></q></dt></tr></i><div id='iLgI0'><tfoot id='iLgI0'></tfoot><dl id='iLgI0'><fieldset id='iLgI0'></fieldset></dl></div>
          <legend id='iLgI0'><style id='iLgI0'><dir id='iLgI0'><q id='iLgI0'></q></dir></style></legend>
            <bdo id='iLgI0'></bdo><ul id='iLgI0'></ul>

                <small id='iLgI0'></small><noframes id='iLgI0'>

                  本文介绍了IntegrityError 在表“orders_order"上插入或更新违反外键约束“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在 Django 1.7 中构建一个电子商务网站,一切正常,但当我尝试使用结帐时,我收到以下错误.我不确定它在做什么,因为它在我的本地主机上运行良好,但当我尝试在 webfaction 上部署时却不行.非常感谢

                  I am trying to build an ecommerce site in Django 1.7 everything works except when I try to use the checkout, I got the following error. I am not sure wht it is doing this as it works fine on my localhost but not when I try to deploy on webfaction. Many thanks

                  Environment:
                  
                  
                  Request Method: GET
                  Request URL: http://myshoppingapp.com/checkout/
                  
                  Django Version: 1.7.1
                  Python Version: 2.7.9
                  Installed Applications:
                  ('django.contrib.admin',
                   'django.contrib.auth',
                   'django.contrib.contenttypes',
                   'django.contrib.sessions',
                   'django.contrib.messages',
                   'django.contrib.staticfiles',
                   'accounts',
                   'carts',
                   'marketing',
                   'orders',
                   'products',
                   'localflavor',
                   'stripe')
                  Installed Middleware:
                  ('django.contrib.sessions.middleware.SessionMiddleware',
                   'django.middleware.common.CommonMiddleware',
                   'django.middleware.csrf.CsrfViewMiddleware',
                   'django.contrib.auth.middleware.AuthenticationMiddleware',
                   'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
                   'django.contrib.messages.middleware.MessageMiddleware',
                   'django.middleware.clickjacking.XFrameOptionsMiddleware',
                   'marketing.middleware.DisplayMarketing')
                  
                  
                  Traceback:
                  File "/home/jamessmith/webapps/myshoppingapp/lib/python2.7/Django-1.7.1-py2.7.egg/django/core/handlers/base.py" in get_response
                    111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
                  File "/home/jamessmith/webapps/myshoppingapp/lib/python2.7/Django-1.7.1-py2.7.egg/django/contrib/auth/decorators.py" in _wrapped_view
                    22.                 return view_func(request, *args, **kwargs)
                  File "/home/jamessmith/webapps/myshoppingapp/src/orders/views.py" in checkout
                    55.       new_order.save()
                  File "/home/jamessmith/webapps/myshoppingapp/lib/python2.7/Django-1.7.1-py2.7.egg/django/db/models/base.py" in save
                    591.                        force_update=force_update, update_fields=update_fields)
                  File "/home/jamessmith/webapps/myshoppingapp/lib/python2.7/Django-1.7.1-py2.7.egg/django/db/models/base.py" in save_base
                    619.             updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
                  File "/home/jamessmith/webapps/myshoppingapp/lib/python2.7/Django-1.7.1-py2.7.egg/django/db/transaction.py" in __exit__
                    339.                         connection.commit()
                  File "/home/jamessmith/webapps/myshoppingapp/lib/python2.7/Django-1.7.1-py2.7.egg/django/db/backends/__init__.py" in commit
                    176.         self._commit()
                  File "/home/jamessmith/webapps/myshoppingapp/lib/python2.7/Django-1.7.1-py2.7.egg/django/db/backends/__init__.py" in _commit
                    145.                 return self.connection.commit()
                  File "/home/jamessmith/webapps/myshoppingapp/lib/python2.7/Django-1.7.1-py2.7.egg/django/db/utils.py" in __exit__
                    94.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
                  File "/home/jamessmith/webapps/myshoppingapp/lib/python2.7/Django-1.7.1-py2.7.egg/django/db/backends/__init__.py" in _commit
                    145.                 return self.connection.commit()
                  
                  Exception Type: IntegrityError at /checkout/
                  Exception Value: insert or update on table "orders_order" violates foreign key constraint "billing_address_id_41625ebca5013523_fk_accounts_useraddress_id"
                  DETAIL:  Key (billing_address_id)=(1) is not present in table "accounts_useraddress".
                  

                  推荐答案

                  重要的细节在这一行:

                  DETAIL:  Key (billing_address_id)=(1) is not present in table "accounts_useraddress".
                  

                  问题是您试图将订单与数据库中尚不存在的帐单地址相关联.

                  The problem is that you are trying to link an order with a billing address which is not yet present in the database.

                  在您的代码中,您需要确保帐单地址已保存到数据库中,然后再尝试保存通过外键与其相关的对象.

                  In your code you'll need to make sure that the billing address is saved to the database before you try and save an object that is related to it by foreign key.

                  这篇关于IntegrityError 在表“orders_order"上插入或更新违反外键约束“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Django模型:两个类之间的相互引用以及在python中无法使用前向声明 下一篇:模型中的外键(用户)

                  相关文章

                  • <bdo id='Ce3JV'></bdo><ul id='Ce3JV'></ul>

                  <legend id='Ce3JV'><style id='Ce3JV'><dir id='Ce3JV'><q id='Ce3JV'></q></dir></style></legend>
                1. <i id='Ce3JV'><tr id='Ce3JV'><dt id='Ce3JV'><q id='Ce3JV'><span id='Ce3JV'><b id='Ce3JV'><form id='Ce3JV'><ins id='Ce3JV'></ins><ul id='Ce3JV'></ul><sub id='Ce3JV'></sub></form><legend id='Ce3JV'></legend><bdo id='Ce3JV'><pre id='Ce3JV'><center id='Ce3JV'></center></pre></bdo></b><th id='Ce3JV'></th></span></q></dt></tr></i><div id='Ce3JV'><tfoot id='Ce3JV'></tfoot><dl id='Ce3JV'><fieldset id='Ce3JV'></fieldset></dl></div>

                  <small id='Ce3JV'></small><noframes id='Ce3JV'>

                  <tfoot id='Ce3JV'></tfoot>