Django 2.1/PostgreSQL - can I prevent deleting model objects?How can I drop all the tables in a PostgreSQL database?Safely deleting a Django model from the database using a transactionDjango script to access model objects without using manage.py shellCorrect Way to Validate Django Model Objects?Django: deleted model objects regenerate themselves in postgresalDjango migration strategy for renaming a model and relationship fieldsHow to prevent django from loading objects in memory when using `delete()`?How to delete the Django model but not the database?How to add “ON DELETE” rules to existing column in a PostgreSQL database table?Trouble with adding rules before deletion of object model
I have a domain, static IP address and many devices I'd like to access outside my house. How do I route them?
Wiring IKEA light fixture into old fixture
Revolutionaries' fleet armed with kinetic weapons defeats government fleet armed with missiles
Can we have too many dialogue tags and follow up actions?
Is it possible to access the complete command line including pipes in a bash script?
What kind of anatomy does a centaur have?
What's the 1 inch size square knob sticking out of wall?
Metaphysical Contemplation and Speculation
Does Impedance Matching Imply any Practical RF Transmitter Must Waste >=50% of Energy?
Get the next element of list in Python
Do Dragonborns get unarmored defense?
Ultraproduct of Dividing Lines
Adding gears to my grandson's 12" bike
Why can't a country print its own money to spend it only abroad?
How am I supposed to put out fires?
How can I indicate that what I'm saying is not sarcastic online?
Why did NASA use Imperial units?
What is the best word describing the nature of expiring in a short amount of time, connoting "losing public attention"?
Do I care if the housing market has gone up or down, if I'm moving from one house to another?
How to plot a crossection of a ParametricPlot3D?
German phrase for 'suited and booted'
Found more old paper shares from broken up companies
Strange LED behavior: Why is there a voltage over the LED with only one wire connected to it?
My current job follows "worst practices". How can I talk about my experience in an interview without giving off red flags?
Django 2.1/PostgreSQL - can I prevent deleting model objects?
How can I drop all the tables in a PostgreSQL database?Safely deleting a Django model from the database using a transactionDjango script to access model objects without using manage.py shellCorrect Way to Validate Django Model Objects?Django: deleted model objects regenerate themselves in postgresalDjango migration strategy for renaming a model and relationship fieldsHow to prevent django from loading objects in memory when using `delete()`?How to delete the Django model but not the database?How to add “ON DELETE” rules to existing column in a PostgreSQL database table?Trouble with adding rules before deletion of object model
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
There were some questions in the past about this but as Django
grows, there are many new database functions.
I'm looking for a way to prevent model
to be deleted from anywhere by anyone.
I have a model Product
and I don't want product to be deleted from database ever.
I understand that overriding delete
is sometimes a good way but I would like to do it on database
level so there is no chance to delete it from shell_plus
or any other source.
In Postgres
, I think, there is a way:
CREATE RULE product_del_protect AS ON DELETE TO product DO INSTEAD NOTHING;
But I would like to do it through Django
so every migrated database will be affected.
There may be a way to do that in model
or custom migration
.
And better would be to raise an error.
django database postgresql django-models
add a comment |
There were some questions in the past about this but as Django
grows, there are many new database functions.
I'm looking for a way to prevent model
to be deleted from anywhere by anyone.
I have a model Product
and I don't want product to be deleted from database ever.
I understand that overriding delete
is sometimes a good way but I would like to do it on database
level so there is no chance to delete it from shell_plus
or any other source.
In Postgres
, I think, there is a way:
CREATE RULE product_del_protect AS ON DELETE TO product DO INSTEAD NOTHING;
But I would like to do it through Django
so every migrated database will be affected.
There may be a way to do that in model
or custom migration
.
And better would be to raise an error.
django database postgresql django-models
1
I don't think a native django solution exists for this, but you can always use raw sql: docs.djangoproject.com/en/2.1/topics/db/sql
– Stargazer
Mar 26 at 14:17
@Stargazer Yes I think combining raw query and migrations.RunPython would be the best way.
– Milano
Mar 26 at 14:22
2
I agree. Just write a migration for that docs.djangoproject.com/pt-br/2.1/howto/writing-migrations
– Stargazer
Mar 26 at 14:23
add a comment |
There were some questions in the past about this but as Django
grows, there are many new database functions.
I'm looking for a way to prevent model
to be deleted from anywhere by anyone.
I have a model Product
and I don't want product to be deleted from database ever.
I understand that overriding delete
is sometimes a good way but I would like to do it on database
level so there is no chance to delete it from shell_plus
or any other source.
In Postgres
, I think, there is a way:
CREATE RULE product_del_protect AS ON DELETE TO product DO INSTEAD NOTHING;
But I would like to do it through Django
so every migrated database will be affected.
There may be a way to do that in model
or custom migration
.
And better would be to raise an error.
django database postgresql django-models
There were some questions in the past about this but as Django
grows, there are many new database functions.
I'm looking for a way to prevent model
to be deleted from anywhere by anyone.
I have a model Product
and I don't want product to be deleted from database ever.
I understand that overriding delete
is sometimes a good way but I would like to do it on database
level so there is no chance to delete it from shell_plus
or any other source.
In Postgres
, I think, there is a way:
CREATE RULE product_del_protect AS ON DELETE TO product DO INSTEAD NOTHING;
But I would like to do it through Django
so every migrated database will be affected.
There may be a way to do that in model
or custom migration
.
And better would be to raise an error.
django database postgresql django-models
django database postgresql django-models
asked Mar 26 at 14:01
MilanoMilano
4,86214 gold badges50 silver badges151 bronze badges
4,86214 gold badges50 silver badges151 bronze badges
1
I don't think a native django solution exists for this, but you can always use raw sql: docs.djangoproject.com/en/2.1/topics/db/sql
– Stargazer
Mar 26 at 14:17
@Stargazer Yes I think combining raw query and migrations.RunPython would be the best way.
– Milano
Mar 26 at 14:22
2
I agree. Just write a migration for that docs.djangoproject.com/pt-br/2.1/howto/writing-migrations
– Stargazer
Mar 26 at 14:23
add a comment |
1
I don't think a native django solution exists for this, but you can always use raw sql: docs.djangoproject.com/en/2.1/topics/db/sql
– Stargazer
Mar 26 at 14:17
@Stargazer Yes I think combining raw query and migrations.RunPython would be the best way.
– Milano
Mar 26 at 14:22
2
I agree. Just write a migration for that docs.djangoproject.com/pt-br/2.1/howto/writing-migrations
– Stargazer
Mar 26 at 14:23
1
1
I don't think a native django solution exists for this, but you can always use raw sql: docs.djangoproject.com/en/2.1/topics/db/sql
– Stargazer
Mar 26 at 14:17
I don't think a native django solution exists for this, but you can always use raw sql: docs.djangoproject.com/en/2.1/topics/db/sql
– Stargazer
Mar 26 at 14:17
@Stargazer Yes I think combining raw query and migrations.RunPython would be the best way.
– Milano
Mar 26 at 14:22
@Stargazer Yes I think combining raw query and migrations.RunPython would be the best way.
– Milano
Mar 26 at 14:22
2
2
I agree. Just write a migration for that docs.djangoproject.com/pt-br/2.1/howto/writing-migrations
– Stargazer
Mar 26 at 14:23
I agree. Just write a migration for that docs.djangoproject.com/pt-br/2.1/howto/writing-migrations
– Stargazer
Mar 26 at 14:23
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55359033%2fdjango-2-1-postgresql-can-i-prevent-deleting-model-objects%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55359033%2fdjango-2-1-postgresql-can-i-prevent-deleting-model-objects%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I don't think a native django solution exists for this, but you can always use raw sql: docs.djangoproject.com/en/2.1/topics/db/sql
– Stargazer
Mar 26 at 14:17
@Stargazer Yes I think combining raw query and migrations.RunPython would be the best way.
– Milano
Mar 26 at 14:22
2
I agree. Just write a migration for that docs.djangoproject.com/pt-br/2.1/howto/writing-migrations
– Stargazer
Mar 26 at 14:23