1

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")

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. :(

Edit: 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.

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()

Perhaps this helps.

MDoe
  • 163
  • 1
  • 13
  • It seems I am not the only one with this problem. This very old post: Django 1.4 Multiple Databases Foreignkey relationship (1146, "Table 'other.orders_iorder' doesn't exist") seems to be pretty much the same. Sadly, there was no solution back then. – MDoe Oct 27 '20 at 09:18
  • The user "Scratte" was so kind and told me that this should be a comment. I want to do this the right way and therefore moved this link. He furthermore wrote: "and since there are in fact an Answer posted on it, the two posts should be linked as duplicates. I think you can flag your own post for close as duplicate." But I am not sure that I understand this correctly, because in the other post there was no solution found except for the direct SQL statement, but neither the author back then nor I am looking for that. – MDoe Oct 27 '20 at 09:22

1 Answers1

0

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
Amir Afianian
  • 2,679
  • 4
  • 22
  • 46
  • I already did this, because I had to work on some other things. Since I wrote my post I did this even twice. And neither makemigrations nor migrate did raise an error. – MDoe Oct 26 '20 at 21:03