Python 3, Django 1.8.5, Postgres
I have a model Sites
that has been working fine. I recently tried to add a field, airport_code, and migrate the data.>
Run into this problem after the migration of my postgres database to a differnt server. Somehow I messed up the database and could not update my model with the new class UserProfile.
I solved the problem creating initial migration for existing schema:
django_migrations
table: delete from django_migrations;
with a command DELETE FROM django_migrations WHERE app='my_app';
migrations
folder: rm -rf /migrations/
python manage.py migrate --fake
python manage.py makemigrations
. Take care of dependencies (models with ForeignKey's should run after their parent model).python manage.py migrate --fake-initial
Got it here: https://stackoverflow.com/a/29898483
PS I'm not sure that this was relevant to the resolution of the problem but, first, I dropped the table in postgresql that caused an error and commented out the UserProfile class in models.
in shell:
sudo -su postgres
psql databse_name
DROP TABLE table_name;
models.py:
#class UserProfile(models.Model):
#user = models.OneToOneField(settings.AUTH_USER_MODEL, unique=True, primary_key=True, on_delete=models.CASCADE, related_name='user_profile')
#avatar = ThumbnailerImageField(upload_to='profile_images', blank=True)
#country = models.CharField(max_length = 128)