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 376515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:36:23+00:00 2026-05-12T14:36:23+00:00

One of my models which has ForeignKey ‘s is actually a MySQL view on

  • 0

One of my models which has ForeignKey‘s is actually a MySQL view on other tables. The problem I’m running into is that when I delete data from these tables, Django, as described in the “deleting objects” documentation…

When Django deletes an object, it
emulates the behavior of the SQL
constraint ON DELETE CASCADE — in
other words, any objects which had
foreign keys pointing at the object to
be deleted will be deleted along with
it.

…tries to remove rows from my view, which of course it can’t, and so throws the error:

mysql_exceptions.OperationalError '>=(1395, "Can not delete from join view 'my_db.my_mysql_view'"'

Is there any way to specify a ForeignKey constraint on a model which will provide me with all the Django wizardry, but will not cascade deletes onto it? Or, is there a way to ask MySQL to ignore the commands to delete a row from my view instead of raising an error?

  • 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-05-12T14:36:24+00:00Added an answer on May 12, 2026 at 2:36 pm

    Harold’s answer pointed me in the right direction. This is a sketch on the way I implemented it (on a french legacy database, hence the slightly odd naming convention):

    class Factures(models.Model):
        idFacture = models.IntegerField(primary_key=True)
        idLettrage = models.ForeignKey('Lettrage', db_column='idLettrage', null=True, blank=True)
    
    class Paiements(models.Model):
        idPaiement = models.IntegerField(primary_key=True)
        idLettrage = models.ForeignKey('Lettrage', db_column='idLettrage', null=True, blank=True)
    
    class Lettrage(models.Model):
        idLettrage = models.IntegerField(primary_key=True)
    
        def delete(self):
            """Dettaches factures and paiements from current lettre before deleting"""
            self.factures_set.clear()
            self.paiements_set.clear()
            super(Lettrage, self).delete()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a modelform which has one field that is a ForeignKey value to
I've the following condition in one of my model which works for mysql. with_scope
I have an edmx model which I have draged 2 tables onto - One
I have two classes (MVC view model) which inherits from one abstract base class.
im having a two models one is companyusers and the other is qualification and
I have the field 'submission' which has a user and a problem. How can
Error: One or more models did not validate: maps.parking: 'layer_id' has a relation with
I have a django application which has one main table/model which references various 'lookup'
I have two models generated with generate scaffolding, one is a LogBook the other
I have a model, Market that has a one-to-many relation to another model, Contract:

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.