问题
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