Can't add a new field in migration: “column .. does not exist”

醉酒当歌 提交于 2019-12-10 10:05:46

问题


I want to add a field to my model but I'm completely lost here. This is the model, the app name is called "profiles":

class Profiles(models.Model):
    user = models.OneToOneField(User, unique=True, null=True)
    nickname = models.CharField(max_length=75, null=True)  # new field
    description = models.CharField(max_length=250, blank=True, null=True)

So, I added the "nickname" field. Then I ran

python manage.py schemamigration profiles --auto
python manage.py migrate profiles

But it gave me an error. "relation profiles_profiles already exists."

So I did

python manage.py migrate profiles --fake
python manage.py migrate profiles

and then when I try to work with the model I get the error

ProgrammingError: column profiles_profiles.nickname does not exist

The message I get when I try to migrate is:

"nothing to migrate"
and 
"nothing seems to have changed"

when I try to do a schemamigration and a migration. :/ ?¿.

I would appreciate any help.


回答1:


The correct command would be:

python manage.py schemamigration <app_name> --auto

You've to write the name of the app, not of the model.



来源:https://stackoverflow.com/questions/24983777/cant-add-a-new-field-in-migration-column-does-not-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!