Question

I just installed django-mptt using PIP (meaning I have 0.5.5), changed an existing model ("Comment") to subclass from MPTTModel, and tried to do a schema migration with South, but South gave me the following error message:

The field 'Comment.lft' does not have a default specified, yet is NOT NULL. Since you are adding this field, you MUST specify a default value to use for existing rows. Would you like to:

  1. Quit now, and add a default to the field in models.py
  2. Specify a one-off value to use for existing columns now

Please select a choice:

In this thread, it looks like the developers suggest telling South to use "0", but then someone else suggests doing so would create another issue. If anyone could shed light on what I may be doing wrong, or how I should respond, I would be very grateful.

Was it helpful?

Solution

As Victor suggested, setting "None" as the default when prompted was the proper course of action. However, it may also be necessary to use the rebuild() method on the model after the migration. I also posted to the django-mptt-dev Google Group, and the package author, Craig de Stigter replied with the following:

If your migration imports the actual models (not the south ORM ones) and does a YourModel.objects.rebuild() at the end of the migration, it should migrate correctly. The actual value you use for the mptt fields in the meantime is irrelevant as the rebuild() will override it.

I asked him to clarify whether he was saying I could specify "None" when asked by South to set a default value, and then go to a shell and use rebuild(), and he said yes.

In any event, it seems to have worked for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top