Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8345131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:35:18+00:00 2026-06-09T06:35:18+00:00

I have a Foreign Key from one model into another model in a differente

  • 0

I have a Foreign Key from one model into another model in a differente database (I know I shouldn’t do it but if I take care properly of Referential Integrity it shouldn’t be a problem).

The thing is that everything works fine…all the system does (relationships on any direction, the router takes care of it) but when I try to delete the referenced model (which doesn’t have the foreign key attribute)…Django still wants to go throught the relationship to check if the relationship is empty, but the related object is on another database so it doesn’t find the object in this database.

I tried to set up on_delete=models.DO_NOTHING with no success. Also tried to clear the relationship (but it happens clear doesn’t have “using” argument so I it doesn’t work either). Also tried to empty the relationship with delete(objects…), no success.

Now I am pretty sure the problem is in super(Object,self).delete(), I can not do super(Object,self).delete(using=other_database) because the self object is not in another database just the RelatedManager is. So I don’t know how to make Django to understand I don’t want even to check that relationship, which by the way was already emptied before the super(Object,self).delete() request.

I was thinking if there is some method I can override to make Django avoid this check.

More graphical:

DB1: “default” database (orders app)

from django.db import models from shop.models import Order

class IOrder(models.Model):

name = models.CharField(max_length=20, unique=True, blank=False, null=False)
order = models.ForeignKey(Order, related_name='iorders', blank=True, null=True)

DB2: “other” database

class Order(models.Model):

description = models.CharField(max_length=20, blank=False, null=False)

def delete(self): 
    # Delete iOrder if any
    for iorder in self.iorders.using('default'):
        iorder.delete()

    # Remove myself
    super(Order, self).delete()

The problem happens when supper(Order.self).delete() is called, then it can not find the table (iorder) in this database (because it is in ‘default’)

Some idea? Thanks in advance,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:35:19+00:00Added an answer on June 9, 2026 at 6:35 am

    I already resolved my issue changing super(Order,self).delete() with a raw SQL delete command. Anyway I would love to know if there is a more proper way of doing this

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was making one table that have two foreign key to another tables. But
I have separate apps with a foreign key from a model in one model
I have two tables, one that has a foreign key from the other. I
I have a model Vehicle and another Model so there's a One-to-Many relationship from
I have a table called TableA whch has a foreign key from TableB and
I have created a foreign key with NaviCat (a MySQL application), but the instant
I designed a database using MySQLWorkbench EER model with many foreign key relationships and
I have a solution that I thought I could take care of model inheritance,
A lot of my models have a foreign key to a Company model. Every
Why can you not have a foreign key in a polymorphic association, such as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.