-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Cannot delete or update a parent row: a foreign key constraint fails - when deleting custom plugin #7737
Comments
@ebugge Thanks for bringing this to attention. Deleting plugins should not be an issue. I certainly cannot reproduce the issue. To clarify the situation:
Can you make the following check in the database:
|
If I understand you last question correctly, then no, there are no double entries in the I have two languages activated on the site, thus, I would expect this table to hold only two rows: One for each language for the single instance of the plugin (screenshot taken before I added one more instance). Isn’t it strange that there are more than two rows? |
You have separate copies for published and draft content. So there can be up to twice as many instances as you might expect. |
I cannot reproduce the error locally. I took a backup of my database on Pythonanywhere, restored it on my own computer and tried deleting the plugin - this works perfectly. I am also able to create a new page with an instance of the plugin, and then delete the plugin again. Not sure what to conclude from this... |
Have you tried "restoring" the database on your production environment? (Export, delete, recover) |
How do you mean restoring on production? Make a new copy of the database and point to that one? I only have one environment on Pythonanywhere and that is production. |
I meant - if you are happy to take the risk
Since after importing at your localhost the issue was gone, it might be that this also fixes the issue with the production database. |
@ebugge Any news on this? |
Sorry, no. I meant to ask you: Any ideas on how this should fix the issue? I am kinda reluctant to do a full delete-and-restore, I must say |
Can you share a database excerpt of the corresponding plugin tree ( |
Did you at any point run the |
@fsbraun Something like this?
I don’t remember whether I have executed |
Looking at the source code (cms/models/pagemodel.py) this is the section that causes the exception. Lines 607-617 in the version of the Django CMS code that I am using.
def _clear_placeholders(self, language=None):
from cms.models import CMSPlugin
placeholders = list(self.get_placeholders())
placeholder_ids = (placeholder.pk for placeholder in placeholders)
plugins = CMSPlugin.objects.filter(placeholder__in=placeholder_ids)
if language:
plugins = plugins.filter(language=language)
models.query.QuerySet.delete(plugins)
return placeholders I guess it makes sense that there is a foreign key from the custom table to the CMSPlugin table? CONSTRAINT `oekf_contactinfo_cmsplugin_ptr_id_e68f18e6_fk_cms_cmsplugin_id` FOREIGN KEY (`cmsplugin_ptr_id`) REFERENCES `cms_cmsplugin` (`id`) I don’t understand how this does not work on Pythonanywhere when it works locally with the same database. I have checked again locally: When I delete an instance of the custom plugin, it is deleted and both the row in Any ideas @fsbraun? |
I have no idea why this happens for our pythopnanywhere database. A bit of a background: When subclassing My suggestion would be to try fixing this by
|
@fsbraun I tried your suggestion. As the plugin is easy to re-create, I deleted all rows of this plugin in both tables: DELETE FROM oekf_contactinfo;
DELETE FROM cms_cmsplugin WHERE plugin_type = 'ContactInfoPlugin’; This was followed by the two After that, I was able to insert a new instance of the plugin on the page and publish without error. But if I try to delete the plugin instance again via the editor interface, I get the same exception. |
This indicates that it is not the database state which is causing the error. What database does pythonanywhere use (and which version)? Django has dropped support for some older MySql versions recently, I believe. |
It should be supported for the Django version I am using. Django: 3.2.21 |
Description
I have a custom plugin that I am unable to delete from my page. The error returned says:
Error seems to occur when the system tries to delete the plugin from the
cms_cmsplugin
table, although it has not deleted the actual plugin from my custom tableoekf_contactinfo
. I am not sure why the row in the custom table exists at this point… Should it have been deleted previously?This is the part of the stack trace where the deletion occurs.
This is my custom plugin definition:
Steps to reproduce
Expected behaviour
I expect that the plugin contents can be deleted from the CMS.
Actual behaviour
See description and steps to reproduce.
Screenshots
None relevant
Additional information (CMS/Python/Django versions)
Python: 3.9
Django CMS: 3.10.1
Django: 3.2.21
I am running the application on Pythonanywhere.
Do you want to help fix this issue?
The text was updated successfully, but these errors were encountered: