Code Monkey home page Code Monkey logo

Comments (8)

gasman avatar gasman commented on August 18, 2024

Thanks @lb- - on_delete is indeed required, as per ForeignKey. Have updated the examples in the readme now.

from django-modelcluster.

BertrandBordage avatar BertrandBordage commented on August 18, 2024

I suggest we reopen this issue.

Updating large projects to Wagtail 2.0 is pretty painful only because of this. The module rename is very easy using the script, but we have to manually add the on_delete=CASCADE attribute on each ParentalKey.

Which brings me to this question: is there any case where we don’t want ParentalKey to be on_delete=CASCADE?
The whole purpose of ParentalKey is to create models that are “contained” in a main model. When we delete a main object like a Wagtail page, we always want the data “contained” in that main object to be deleted as well. So ParentalKey should always have CASCADE behaviour as far as I can tell.

And therefore, what’s the point of having to manually specify it? We could force on_delete=CASCADE on ParentalKeys and don’t even accept any optional on_delete argument since it wouldn’t make sense.

Side note:

When I worked on some advanced closed-source cross-models importer, I always took the assumption that on_delete=CASCADE meant that the model is “contained” in another model. In a correctly designed database, that’s what CASCADE means. All that to explain that not only ParentalKeyCASCADE, but also CASCADEParentalKey in a correctly designed database.

from django-modelcluster.

mhope-2 avatar mhope-2 commented on August 18, 2024

on_delete=models.CASCADE giving errors, requires arguments

from django-modelcluster.

mhope-2 avatar mhope-2 commented on August 18, 2024

TypeError: CASCADE() missing 4 required positional arguments: 'collector', 'field', 'sub_objs', and 'using'

from django-modelcluster.

gasman avatar gasman commented on August 18, 2024

@setriakorm You shouldn't put () after CASCADE. If that's not the issue, please provide specific steps to reproduce this error.

from django-modelcluster.

mhope-2 avatar mhope-2 commented on August 18, 2024

from django-modelcluster.

zhenfengcao avatar zhenfengcao commented on August 18, 2024

I think the best way would be allowing users to set on_delete to a default value for all cases in settings.py. If not set, then it would be a required argument; if set, then use that default value for all cases.

from django-modelcluster.

gasman avatar gasman commented on August 18, 2024

@morningmorningwind I disagree... we want this package to be as useful and friendly as possible in its default configuration. on_delete=CASCADE is the right choice for ParentalKey in every scenario we can imagine, so it makes sense for it to be the default. Moving it into a configuration option is a poor way to serve users - it means that only the users who take time to read through all the configuration options will benefit from this.

from django-modelcluster.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.