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.