samedi 6 février 2016

django local field clashes with nonexistent field of deleted parent class

I am trying to change my model in my django project. I'm a total django noob.

Previously: In a common application, an Image model used a File class (defined in the same file) as a base class. The File class had a filename field, but I can't remember if the Image class did ( I don't think that would have worked, but the error message shown below makes me question that).

I'm Attempting: make the Image be completed independent of File, and remove the File model. It has no filename field.

To do this, I removed the definition of File from models.py , removed the filename field from Image, then ran manage.py makemigrations.

The remaining class definition for Image:

class Image(models.model):
    name=models.CharField(max_length=100)

However, when I run python manage.py makemigrations, I receive the following error:

$ python manage.py makemigrations
...
django.core.exceptions.FieldError: Local field 'filename' in class 'Image' clashes with field of similar name from base class 'File'

Clearly Image is not dependent on File, and should not have filename field in the updated model.

Also, I manually removed the tables for Image and File from the sqlite database, but it didn't seem to change the output or error.

I also tried changing the name of the "Image" class to be "MyImage", but this to did not seem to have any effect on the output.

So, it does not seem to be the database or the models file which is causing the error.

So, my questions are:

  • what and where are the migration files that are causing the field clash error?
  • how can I get the database to reflect my desired model?

I'm using django 1.9.1, with an sqlite database.

Aucun commentaire:

Enregistrer un commentaire