<bdo id='uTqTA'></bdo><ul id='uTqTA'></ul>

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

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

        如何解决 Django 中有关外键的 DeleteView 问题?

        时间:2023-07-06
          • <bdo id='k0cqK'></bdo><ul id='k0cqK'></ul>

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

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

                  <tfoot id='k0cqK'></tfoot>
                  本文介绍了如何解决 Django 中有关外键的 DeleteView 问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我必须使用应用程序(DMS 和 ObjPDW).第一个是用于管理一些文件.在这我有一个模型 DMS_Dokument,其中包括一个 FileField 等等.最近我为后一个应用程序(ObjPDW)添加了一个新模型,并在 Dokument_DMS 中添加了一个外键:

                  I have to apps (DMS and ObjPDW). The first one is for managing some files. In this I have a model DMS_Dokument, which includes a FileField and some more. Recently I added a new model to the latter app (ObjPDW) and I included a foreign key to Dokument_DMS:

                  class Zahlungsstrom(models.Model):
                      zahlung_bezeichnung = models.CharField(max_length=550, blank=False, null=False, verbose_name="Bezeichnung")
                      zahlung_betrag = models.DecimalField(max_digits=7, decimal_places=2, default=None, blank=True, null=True)
                        zahlung_dok_fk = models.ForeignKey(dmsdok.DMS_Dokument, on_delete=models.SET_DEFAULT, default=None, null=True, blank=True, verbose_name="Zahlungsdokument")
                  

                  现在我想删除一个 DMS_Dokument 对象(使用 DeleteView CBV),但它给了我一个prorammingerror":(1146,表'DB_DMS.ObjPDW_zahlungsstrom'不存在")

                  Now I wanted to delete a DMS_Dokument object (using the DeleteView CBV), but it gives me a "prorammingerror": "(1146, "Table 'DB_DMS.ObjPDW_zahlungsstrom' doesn't exist")"

                  我不知道问题是什么.:(

                  I have no clue what the problem is. :(

                  只是为了明确这一点.这两个应用程序都有自己的数据库.我知道 Django 不建议在两个数据库之间关联模型,但由于我不是经验丰富的程序员,我不知道为什么我可以使关系工作,但删除是个问题.

                  Just to be clear on this. Both apps have their own databases. I know that Django is not recommending to relate models between two databases, but as I am no experienced programmer I do not know why I can make the relations work, but deletion is such a problem.

                  此外,我想在此处包含更多代码,这是关于 DMS_Dokument 模型的.它还有一个删除定义.

                  Furthermore I want to include some more code here, which is about the DMS_Dokument model. It also has a delete def.

                  class DMS_Dokument(models.Model):
                      dms_dok_titel = models.CharField(max_length=255, blank=True)
                      dms_dok_beschreibung = models.CharField(max_length=3000, blank=True, null=True)
                      dms_dok_datei = models.FileField(max_length=255,upload_to='DMS/')
                      dms_dok_gehoert_zu_app = models.CharField(max_length=255, choices=app_choices, blank=False, null=False)
                  
                      def save(self, *args, **kwargs):
                          preserve_ext = extension(self.dms_dok_datei.name)
                          neuer_dateiname = self.dms_dok_gehoert_zu_app + '_' + self.dms_dok_titel + '_' + self.dms_dok_hochgeladen_am.strftime("%d.%m.%Y")
                          self.dms_dok_datei.name = neuer_dateiname + preserve_ext
                          super(DMS_Dokument, self).save(*args, **kwargs)
                  
                      def delete(self):
                          self.indexes.all().delete()
                          super(DMS_Dokument, self).delete()
                  

                  也许这会有所帮助.

                  推荐答案

                  报错说表不存在.您必须发出以下命令来创建迁移并在您的数据库中创建表:

                  The error says the table does not exist. You must issue the following commands to create the migrations and make the table in you DB:

                  python manage.py makemigrations
                  python manage.py migrate
                  

                  这篇关于如何解决 Django 中有关外键的 DeleteView 问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 to_sql 和 sqlalchemy 到 mariadb 数据库的 pandas 数据框 下一篇:将 Python3 连接到 MariaDB 的困难 - 取 1

                  相关文章

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

                    <legend id='NrUxT'><style id='NrUxT'><dir id='NrUxT'><q id='NrUxT'></q></dir></style></legend>

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