South cannot create a new field because the field does not exist

I am trying to use South to add a new URL field to the model, for example:

class Document(models.Model): text = models.TextField() reference_page = models.URLField(blank=True, null=True) source_page = models.URLField(blank=True, null=True) # new field 

However, when I run python manage.py schemamigration myapp --auto , I get an error:

 DatabaseError: column myapp_document.source_page does not exist LINE 1: ...ext", "myapp_document"."reference_page", "myapp_doc... 

I am using PostgreSQL as my DB. I correctly initialized my application for the South and have already completed the migration. I made sure my Django and South installations were updated.

Why am I doing this now?

Edit: Oddly enough, if I manually created a column in the database, the schemamigration call succeeds, but, of course, the migrate call fails, until I manually delete the column. This is strange.

+4
source share
2 answers

I have been dealing with this issue for a couple of months. The link provided by montiniz in a comment on another answer had a 0-voted answer that solved my problem! I post it here to help someone else. Build a knowledge community and all that.


Problem: schemamigration [app] --auto fails with a complaint about a missing column (often for a new field for which you are trying to migrate a schema ...)

In my case, he will complain only when the Workgroup model (model.py Model ) changes, but not on other models.

Solution: Look for another model that has a default keyword argument in relation to ForeignKey , which refers to a model that is not portable.

workgroup = models.ForeignKey('core.Workgroup', default=get_default_workgroup, null=True)

If you remove the default keyword argument, then run the control command, it will succeed. Then just add the original default argument.

+6
source

Check migration files, especially models . Looks like someone was messing with him. If the current migration number is 10, then models in migrations 9 and below should not have this new field specified in it. If it is there, then delete it.

+1
source

Source: https://habr.com/ru/post/1500403/


All Articles