2

I have a model like this :

class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    address = models.CharField(max_length=100)
    city= models.CharField(max_length=100)

, after a while, I add 2 more fields to this:

zip_code = models.CharField(max_length=20, blank=True, null=True) state = models.CharField(max_length=50, blank=True, null=True)

, then I do the routine

python manage.py makemigrations
python manage.py migrate 

But when I go to website/admin and check that model in Django Administration, I got the error "column user_profile.zip_code does not exist"

I search for the solution and some threads suggested to use South but then I learned that from django >= 1.7 we don't need to use South for migrations.

Please show me where I am wrong.

Thank you!

Huy Than
  • 1,538
  • 2
  • 16
  • 31

3 Answers3

0

Check that you use the same settings when running migrate and the server.

Tomas Walch
  • 2,245
  • 1
  • 14
  • 17
0

If you are using django debug toolbar in your installed apps. Make sure to comment that, that gives the issue. If not, you can also check if your models are used by forms in another app or not. If they are its better to move the logic into views.

Rajat Vij
  • 689
  • 1
  • 6
  • 12
0

I commented out the debug toolbar, but that did not solve the problem.

I was adding a field to the user model. I have a utility that returns the default user. When I tried to migrate (adding the new field), that utility was getting called and was causing the error.

The solution that worked for me: in the utility that returns the default user, temporarily commenting out calls to the user table, and returning None for the default user. Migrate then ran successfully. Then of course I restored the code in the utility.

I found out that my utility was causing the problem by finding a line from my code in long list of exceptions displayed in the terminal.

Rick Graves
  • 517
  • 5
  • 11