3

I created a CustomUser model, inheriting from AbstractEmailUser.
I wanted to add an avatar field, after finishing it and making migrations but I'm getting the following error:

column account_customuser.avatar does not exist
LINE 1: ...user"."name", "account_customuser"."valid_email", "account_c...

models.py looks like this now

class CustomUser(AbstractEmailUser):
    nickname = models.CharField('nickname', max_length=100, unique=True)
    name = models.CharField(max_length=200, blank=True, null=True, default=None)
    valid_email = models.BooleanField('valid email', default=False, blank=True)
    avatar = models.ImageField(upload_to='profile/photo', blank=True, null=True, default=None)

What can I do to correctly add the avatar field?

John Moutafis
  • 22,254
  • 11
  • 68
  • 112
alex
  • 2,381
  • 4
  • 23
  • 49

2 Answers2

3

As stated here: Django Programming error column does not exist even after running migrations

Something may have gone wrong in your migration process.

  1. Go to your database and find a table named django_migrations where all the migrations are listed.
  2. Find the row with the migration in which you added the avatar column to your model and delete it from the database (only the row).
  3. Migrate again: ./manage.py migrate

Another possibility is that you are using Django Toolbar like what happened here: Django Migration Error: Column does not exist, in which case you need to comment the toolbar in your installed apps and rerun migrations.

John Moutafis
  • 22,254
  • 11
  • 68
  • 112
0

Did you apply a new migration with these changes? You can check this using showmigrations or use makemigrations to create a migration and migrate to apply it.

Mr. Nun.
  • 775
  • 11
  • 29
  • yes, i have, i have even deleted all migrations and remigrate everything, still getting it, do i have to delete the postgres tables? – alex Oct 02 '17 at 07:42
  • Before deleting tables you can try remove record from "django_migrations" about migration with this changes. Or create new migration with changes and apply it. – Yahor Tsyplakou Oct 02 '17 at 08:10