There are some items that are not deletable or editable from my Django sqlite3 database. When trying to delete these items, I get
integrity error: foreign key constraint failed.
The frustrating thing is that this isn't the case with the majority of items in my database. I believe it is only affecting a few rows, which I must have created before making some tweaks to the models. I don't recall what exact changes I made to the
models.py file, but I don't think it was anything drastic. I don't have information about the migrations I made, because I deleted these files thinking that it might resolve the problem.
I have included an example of how the classes in
models.py are currently set up. Nothing complicated, standard models with a simple foreign key, which isn't even a required field.
I have tried editing my migrations files, completely removing my migration history, editing the models via
class ExampleOne(models.Models): title = model.CharField(max_length=500, null=True, blank=True) class ExampleTwo(models.Models): title = model.CharField(max_length=500, null=True, blank=True) example_one = models.ForeignKey(ExampleOne, null=True, blank=True, on_delete=models.CASCADE)
I'd rather not delete my database file. I'd to be able to delete these instances of exampleone and exampletwo, but when I try to delete any item created before I had tweaked my model files, I get the error:
django.db.utils.IntegrityError: FOREIGN KEY constraint failed